What are you trying to accomplish e.g. I want to integrate builder on a landing page
We have spent months working on this page. It includes quite a few elements that leverage custom code (JS).
On the page preview (which features ?apiKey in the URL), everything functions as designed. However, after publishing the page and upon visiting it at its designated URL, none of the custom JavaScript appears to be working. This is specifically code stored in the sidebar “Custom Code/CSS” area.
There are no errors reported in the dev console, so no readily apparent reason for this behavior. Why is this happening, and what can we do to fix it?
Code stack you are integrating Builder with e.g. NextJS, react, Shopify React
Hi @ReavoEnd this is a very strange issue… we have done more investigating and for some reason the custom JS code doesn’t run on your live page.
I tried adding a Custom Code block with some console.logs. The console.logs are successful until I paste in your custom code, then nothing runs, which leads me to believe there is something in your custom code that is technically correct but for some reason the browser doesnt like.
We have seen this before where a browser will have strict linting and if it doesnt like it it will just remove it or not run the code. I would suggest commenting out sections of the code until you can diagnose which parts run and wont run.
I will try to spend more time digging on our end, but if you have any further insights that might help! I created a duplicate of the page: Builder.io: Drag and drop Visual CMS at Bigscreen
To be able to test without affecting your homepage
Thanks for looking into this. That’s a helpful lead, sounds promising. I’ll look into what parts of the code could be considered unconventional to a linter.
It does seem to me that if this were an issue with the browser’s linting, it would surely output console errors or warnings of some sort. Given that it doesn’t, could the issue have more to do with the linter in Builder’s backbone, i.e. React or what-have-you?
I’ll keep digging around based on this lead. Will report back if I find anything more specific.
Ok, so I’ve now tried commenting out all of the code in Edit Content JS + CSS except for a single console.log() call.
• On the preview site, the new console message appears in the dev console
• On the published/live site, the new console message does not appear in the dev console
This indicates to me that the issue does not involve the custom code I wrote in that section of Builder.io. It must lie elsewhere…
Oh, one more thing about the test you ran with a custom code block.
If you pasted my custom code as-is, that would definitely not work because the custom code blocks strip out all the newlines. My custom code has a bunch of standard-form //text here comments, and this style of comment breaks JS scripts in custom code blocks. Just FYI!
How are you checking the outcome of your tests? Are you able to see the published page on an internal portal? Just a reminder that the JS issue I’m encountering is only on published pages, and do not manifest in the editor GUI or the page preview.
Edit: Had another thought. Some of my custom code interacts with Builder’s state. If I recall correctly, state is not accessible from a custom code block.
@ReavoEnd we were testing to a published dummy page at https://dev-egg-website.bigscreencloud.com/pages/home-tester-builder
And yes, I also noticed that actually commenting out all custom code still did not run the Custom JS code… which to me indicates something in your app is blocking the JS from running. I can’t recreate this same issue in any of our Shopify testing spaces either.
I actually copied your code into a testing space of mine and published the page and the code was seemingly running without issue, so it definitely seems to be interacting with something in your app in an unexpected way.
Do you know if any other pages or model types have the same issue across your site? Is it true of all page models?
I haven’t found any new leads, but I did a little more digging in the Fetch / XHR tab in the Network dev panel. I was able to confirm that the published page fetches from the builder CDN via:
Yes, I noticed that too. I am still investigating, but I think the issue is that your space is setup as a Shopify space, not a CMS (headless) space. So the reason everything “works” in preview and the visual editor is because you are actually previewing/editing on a page in Shopify, not within your app. Generally if you are going to have a headless web-app or non-Shopify hosted web-app, we would recommend customers to have that content in a separate CMS space.
I am still surprised that the JS code doesn’t run, so I am looking through our code to see if there is a reason for that and how we can fix it in the meantime, but will get back to you when we have more! Appreciate your patience on this issue!
Is that really the case? I’m compelled to believe contrary. Our page model’s preview URL is set to dev-egg-website.bigscreencloud.com. Back when we were setting up our React instance to serve the builder.io page, both the editor GUI and the page preview would not load until we had everything setup correctly on our server. This would appear to indicate that the page model does not lean on Shopify to render at all.
Anyway, thanks for looking into this so thoroughly. Hoping we can resolve today!
In case it helps: Our testing domain is IP-whitelisted, so if the editor/preview/published pages don’t load for you, that’d be why.
If being on the whitelist would help you diagnose the issue more efficiently, we can add you temporarily and until a resolution is reached. Just let me know in a DM with your IP address.
Hi @ReavoEnd ok I checked your setup again and you are correct that the preview is not on Shopify.
I tried it out, and I am not exactly sure why but for some reason useEffect does not play well with the custom JS, and I confirmed that is true across all spaces. It might be something with the timing of how useEffect updates content end affects rendering? But the good news is it doesn’t matter!
You actually shouldn’t need to use useEffect at all. Since you are doing client-side rendering as long as you pass the urlPath to the you should be getting the correct content. Try something like this: