Debug a React hydration mismatch between server HTML and the client
Answer: hydrateRoot() expects the rendered content to be identical with the server-rendered content. Treat mismatches as bugs and fix them. That mismatch is the React tree prerendered from the server versus the first render in the browser.
What React checks
Hydration attaches event handlers so the prerendered HTML from the server becomes a fully interactive application. React warns about mismatches during hydration when you are in development mode. Attribute differences have no guarantees they will be patched up. React will clear the existing server-rendered HTML content if root.render runs before that root has finished hydrating.
Common causes
| Hydration errors | Rendering logic | |---|---| | Incorrect nesting of HTML tags | A <p> nested in another <p>, or a <div> or <ul> nested in a <p>. Interactive content such as an <a> must not be nested in an <a>. | | Browser-only APIs | typeof window !== 'undefined', window, or localStorage in your rendering logic. | | Time-dependent APIs | The Date() constructor in your rendering logic. |
How to fix it
Render the same content server-side as during the initial client-side render. If you intentionally need to render something different on the server and the client, use two-pass rendering: read a state variable like isClient and set it to true in an Effect. Next.js can disable prerendering on specific components with dynamic(..., { ssr: false }).
If a single element's attribute or text content is unavoidably different (for example, a timestamp), add suppressHydrationWarning={true}. This only works one level deep, and is intended to be an escape hatch. React will not attempt to patch mismatched text content.
See also
Claims
- id: C1 claim: hydrateRoot expects client output to match the server HTML. source: S1 evidence: "expects the rendered content to be identical with the server-rendered content"
- id: C3 claim: Invalid HTML nesting is a common hydration-error cause. source: S2 evidence: "Incorrect nesting of HTML tags"
- id: C4 claim: suppressHydrationWarning only silences one element level. source: S2 evidence: "This only works one level deep, and is intended to be an escape hatch."
Sources
- [S1] hydrateRoot. React docs. https://react.dev/reference/react-dom/client/hydrateRoot . License: CC-BY-4.0. Accessed 2026-11-19.
- [S2] Text content does not match server-rendered HTML. Next.js docs. https://nextjs.org/docs/messages/react-hydration-error . License: MIT. Accessed 2026-11-19.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: React docs, hydrateRoot; Next.js docs, Text content does not match server-rendered HTML. CC-BY-4.0; MIT. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: React docs, hydrateRoot; Next.js docs, Text content does not match server-rendered HTML. CC-BY-4.0; MIT.
Cite this
iinventedlight. 2026. "Debug a React hydration mismatch between server HTML and the client." iinventedlight Library, iil:note:9ewsq1yq, version of 2026-11-19. https://iinventedlight.com/library/notes/react-hydration-mismatch/. License: CC-BY-4.0.
@misc{iil_note_9ewsq1yq,
author = {{iinventedlight}},
title = {{Debug a React hydration mismatch between server HTML and the client}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/react-hydration-mismatch/},
note = {Permanent ID iil:note:9ewsq1yq. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- react-hydration-mismatch.table.json (table; CC-BY-4.0)
- react-hydration-mismatch.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/react-hydration-mismatch.md.