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

Skip script rendering after hydration #422

Merged
merged 4 commits into from Dec 15, 2021
Merged

Conversation

developit
Copy link
Collaborator

@developit developit commented Nov 22, 2021

This is a small tweak to @jacob-ebey's #403 that removes the window property. It achieves the same result as #390 but with minimal changes to Remix and no hydration mismatch concerns. Remix's components module is only instantiated once, so a module variable is sufficient for tracking isHydrated state.

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Nov 22, 2021

Hi @developit,

Welcome, and thank you for contributing to Remix!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run.

Thanks!

- The Remix team

@developit developit changed the base branch from main to dev November 22, 2021 15:47
@developit developit mentioned this pull request Nov 22, 2021
3 tasks
@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Nov 22, 2021

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

@ryanflorence
Copy link
Member

Can ya'll help me understand what this is solving? The script entries only ever render once and then they never change because of the useMemo. Why do we need to remove them from the page after hydration?

@developit
Copy link
Collaborator Author

developit commented Dec 2, 2021

@ryanflorence the script elements do re-render when the whole tree gets remounted due to an error or redirect. Memoization doesn't help there.

The reason for this PR is because Preact doesn't emulate parser-created <script>, so rendering these on the client (barring during hydration) executes the new scripts.

@ryanflorence
Copy link
Member

well crap ... tests pass locally for me

@ryanflorence ryanflorence merged commit d4860a0 into dev Dec 15, 2021
@developit developit deleted the developit/script-hydration branch December 15, 2021 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants