question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hydration fails when a component is used on multiple pages

See original GitHub issue

Version: 1.1.0-next.3

Steps to reproduce

  1. Render a hydrated component on multiple pages
  2. Build/serve
  3. Load in browser

Expected behavior

The component will hydrate on each page.

Observed behavior

No JS is loaded at all.

Apparent cause

Any shared component with hydration is bundled as a shared chunk, but the shared chunk is excluded from hydrateBindings, and doesn’t appear to be referenced anywhere else. If I comment out that check it does hydrate as expected.

I was tempted to offer a PR removing that check, but I can’t shake the feeling that there’s a reason it’s there and the intent was to handle that case differently.


Related side note: in terms of contribution, my usual approach is to write a failing test exercising my bug, then fix to make the test pass. But at present Microsite doesn’t appear to have a test suite. Is that something you’d be interested in? If so do you have a preferred test framework? I’d be happy to look into setting up CI for any tests I contribute, and to try to increase coverage as I contribute.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
eyelidlessnesscommented, Jan 25, 2021

Without getting too hung up on the big testing question, I strongly suspect the resolution of this is pretty simple:

  1. Shared hydration chunks and shared static chonks should go to different manual chunks
  2. Shared hydration chunks should go to the bundle
  3. Eventually the implicit TODO should be addressed and allow more granular code splitting
  4. For my own use I’m gonna want to bundle up everything headed to the client and un-split but that’s obviously not a requirement here. Just stating my use case!
1reaction
eyelidlessnesscommented, Jan 22, 2021

Great news! I got a little proof of concept with Estrella working, and goodness it is fast! And it took very little fuss to get going. I’m going to clean up some mess, setup a GitHub Action, and push up a PR. It’s not a huge diff, but I think I’d like to keep test setup separate from fixing this issue to get a meaningful win. Hopefully ready within the hour!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hydration failed because the initial UI does not match ... - GitHub
When I use getStaticProps to get the json data and show data to the pages that has this problems. problem 1. Hydration failed...
Read more >
react-hydration-error - Next.js
An example of this is using window in a component's rendering. Another example: Invalid HTML may cause hydration mismatch such as div inside...
Read more >
Debugging and fixing hydration issues - somewhat abstract
Spotting hydration errors and fixing them can prevent serious user-facing performance issues, and since we do not get a signal during production ...
Read more >
React 18: Hydration failed because the initial UI does not ...
Got rid of the component, and it works fine now. (I could have changed the component config to use a different element. But...
Read more >
Handling the React server hydration mismatch error
How to resolve the server mismatch error when hydrating a shared React component that can be used in client-side only or server-side ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found