Preview URL not working with client-side rendering

No! Gosh I got excited when I saw your answer…a glimmer of hope in a long dark passage!

I didn’t realize you could fetch content with the content id! The “entry” option is missing entirely from the content API documentation page ( Content API ).

I am storing the content ID in the database record for each landing page, which I get when I create the page with the with Write API. So my code is a little different than yours…

  useEffect(() => {
    async function fetchContent(contentId) {
      if(!isLoading && !content) {
        setIsLoading(true);
        console.log('Fetching content for ID:', contentId);
        const content0 = await builder
          .get(builderModelName, {
            entry: contentId
          }).promise().catch((error) => {
            console.error('Error fetching content:', error);
            setIsLoading(false);
          });
        setContent(content0);
        setNotFound(!content0);
        console.log('Fetched content:', content0);
        setIsLoading(false);
      }
    }
    if(selectedLandingPage){
      fetchContent(selectedLandingPage.content_id);
    }
  }, [selectedLandingPage]);

Using the content ID to fetch the content is much more robust than using the URL. Why is this a hidden option?

So when I use this code in my CRA app the preview URL again works standalone but not in the visual editor. In the console it appears that the fetch is started but never finishes. Here are the two console logs…

For the visual editor…

For the standalone preview…

So thanks for the help…let me descend now into my long dark passage.