Javascript is not evaluated when page open

@Jediinspace We do run JS on initial page load, and I took a look at your page and was able to confirm that is the case here as well. I have added a console.log in the custom JS window, you can see that console.log is indeed being logged to the console on first load, so I don’t think that is the issue here. That being said, there does seem to be some timing issues that are preventing the state from being correctly set on first load within the Editor.

First, the async/await pattern you used seemed to be getting hung up and taking awhile or timing out. I updated to use the Promise that is returned as part of the fetch API and am getting a much more consistent response, please check it out and see if that change works for you.

I will continue to investigate any issues on our end to see if there is something preventing the content from being available on first load within Editor. In the meantime, the good news is that:

  1. The preview page, and the production page once published, don’t seem to have this issue anymore, as I am able to consistently load the correct data here:
    Content Preview Page
  2. I think a lot of these issues will be resolved if you implement the change I outlined in my response to your other post here: Can't get reference field data in state - #3 by Jediinspace Which will remove the call to the content API completely and make it much easier to access the necessary data directly on the page.

Let me know if this all makes sense and is helpful!