Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pause render until new head scripts are loaded #377

Open
markjerz opened this issue Sep 6, 2021 · 0 comments
Open

Pause render until new head scripts are loaded #377

markjerz opened this issue Sep 6, 2021 · 0 comments

Comments

@markjerz
Copy link

markjerz commented Sep 6, 2021

Hi,

Sort of related to #28 ...

When merging new head scripts in to the head these are currently done asynchronously (as it's not possible to do synchronously). To my mind though, this breaks the way that html page loading is done in the browser. If, in a vanilla request, I add a script (without async and defer attributes) it is loaded before the rest of the page is rendered so that it is then available to the rest of the page. In turbo though, any scripts in the body are usually executed before those scripts have been loaded.

Various workarounds seem to be:

  • turn off turbo for those pages
  • bundle your JS and load on every page
  • manual pausing

I really feel like a generic solution (maybe opt-in) is possible here that will wait for the script elements to be loaded script.addEventHandler('load', ...) before resuming the render.

Would it be as simple as making the mergeHead method in the SnapshotRenderer of the async?
If that were not possible, a nice addition to the pausable api would be the provision of the new scripts alongside the new body so that users could wait for their scripts manually when necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant