Please fill out as many of the following questions as possible so we can help you promptly! If you don’t know how to answer or it does not apply, feel free to remove it or leave it blank.
Builder content link
Detailed steps to reproduce the bug
I have tried to add a basic log line to the Builder.IsBrowser block in the JS editor as a debugging step for understanding why my custom fetch request wasn’t working. I was surprised to learn that even this console.log doesn’t work once the page has been published.
Code stack you are integrating Builder with
React only
Reproducible code example
/*
* Global objects available:
*
* state - builder state object - learn about state https://www.builder.io/c/docs/guides/state-and-actions
* context - builder context object - learn about state https://github.com/BuilderIO/builder/tree/main/packages/react#passing-data-and-functions-down
* fetch - Fetch API - https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API'
* Builder - Builder object - useful values include: Builder.isServer, Builder.isBrowser, Builder.isPreviewing, Builder.isEditing
*
* visit https://www.builder.io/c/docs/guides/custom-code
* for more information on writing custom code
*/
async function main () {
if (Builder.isServer) {
// Place any code here you want to only run on the server. Any
// data fetched on the server will be available to re-hydrate on the client
// if added to the state object
}
if (Builder.isBrowser) {
// Place code that you only want to run in the browser (client side only) here
// For example, anything that uses document/window access or DOM manipulation
console.log('is browser4');
}
}
export default main();
Hi @tomMisson, I can’t access your page (Error 1020: Access Denied) making this difficult to debug. Could you share your fetch request or perhaps DM me with access? Thanks
The console in the builder interface shows the log lines absolutely fine but the live page doesn’t show the log lines and also doesn’t attempt the fetch (can be seen in the network tab)
Hi @tomMisson thanks so much for sharing the public version. I do see that the console.log() message is not appearing on your live page but I’m unable to reproduce this behavior independently in my own test space with your fetch. (Here’s a fiddle where I use your fetch call [Fiddle], and here’s the live page where it logs ok in the console [Live]). Could there be something in your code for that page template suppressing console logs?
Hi @ancheetah, hmmm very odd indeed, we don’t have anything that would strip them out/supress them…
I have updated the fiddle to accurately reflect what we are trying to do as console logging was not really a concern of ours, more that the results of the fetch aren’t loading… Fiddle
When the fiddle is updated to map data in to components, it works in the preview but not the published page.
@tomMisson I’ll bring this bug up with our engineering team and update you here when we have a solution. In the meantime, a workaround could be to fetch from both your endpoints in the Content API Data section in the Data tab then use custom JS to map the authors from one dataset to the other. Hope this helps!
Hi there! Was wondering if there has been any progress with this bug? I believe it may have manifested itself in another form…
When creating a Content Input, setting its value and then copying the page contents to another space, the value of the input in the state becomes undefined when published, despite its value being set.
Content inputs are more commonly used with symbols but you can also use them the way you mentioned if you need to. It sounds like this issue may also be related to your previous bug because I am not able to reproduce.
I see that you have unpublished the page in your public workspace that you shared. Our team can’t reproduce on our side without seeing the page, so I think a screenshare would be helpful. Someone will be reaching out by email to see if we can offer further support.
I have some JS code on the page that’s fetching some data from one of our APIs. It works in the editor and when previewing, but the code doesn’t execute once published.