Javascript is not evaluated when page open

@Jediinspace definitely not, apologies if my previous answer was unclear in that regard…I have created an internal ticket to investigate why some data doesn’t seem to be available initially on page load within the editor and will be sure to get back to you with any updates.

That being said, it could potentially be a complex and involved investigation, so with my previous response I was hoping to provide a few work arounds in the short term to help get the page working. I took another look at the page and noticed a few issues that resulted in the ‘undefined’ title that I have tried to clean up.

Firstly, in the JS window, it looks like you had set insuranceType, currentInsurance, partners to const variables, which aren’t globally available.

const insuranceType = ...
const currentInsurance = ...
const partners = ...

Instead, you should set those to state so that those values will be accessible within the page.

state.insuranceType = ...
state.currentInsurance = ...
state.partners = ...

For the title text itself, the data binding was set to state.insuranceCategories.results.find(i => i.data.slug === state.insuranceType)); which actually returns an insuranceCategory object, not the name I think you wanted. I updated that binding to:
state.insuranceCategories.results.find(i => i.data.slug === state.insuranceType).data.content.find(i => i.lang === state.lang).name);
and it is now returning correctly and consistently.

Hopefully that helps! I recommend checking out further resources on advanced data fetching:

and adding custom code:

To see if there is further helpful info there. I will keep you updated on any info as we investigate why data is sometimes slow to load on initial page in the editor, but hopefully this gives you some places to go as you set up your pages.

Lastly, not sure if you saw my response about including referenced models in your state: Can't get reference field data in state - #5 by TimG but I would recommend trying to implement that as well, it may further reduce reliance on any client-side logic.

Let me know if you have any other questions, always happy to help!