0

Sometimes with hydration I get super helpful error messages like "img tag's src attribute was X from the server but Y in the browser", etc. but in production, I am getting a very opaque message:

Text content does not match server-rendered HTML.

The only option I can think of at this point is shipping a dev build to production to try to get better feedback. Is there any other addon tooling out there to add context to hydration errors for debugging purposes? Or is a dev build my only option

1 Answer 1

1

Hydration issues happen because of mismatches between SSR and client-side rendering.

First of all, it's no big deal. It might be happening because you're generating something in a way that's inconsistent between node and the browser (random number, size calculation, floating points, jsdom inconsistencies, etc). The client-side render will paint over any inconsistencies.

Finding them is fairly straight-forward. Hit CTRL-U in the browser to see the html output from the server, and then compare it to the html in the browser console. Use your diff tool of choice to compare the two.

A dev build won't help you much more than this process. The diff tool will flag the discrepency.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, it didn't occur to me to do just do the diff myself. I'll give this a try
Thanks, this did it. It was a timezone server vs client issue
I am still having this problem, but there is nothing when I run the diff. the server html has stuff like the initial data in script tags, but that is to be expected. There is no diff in the react mount point.
If you register a mutation observer before React has a chance to render, you could compare the output of the SSR and the first render. The difference might be getting reconciled via an effect.
I tried adding a Mutation Observer as well, no luck. No difference that I can find in the server generated html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.