---
source: https://iinventedlight.com/library/notes/react-hydration-mismatch.md
title: "Debug a React hydration mismatch between server HTML and the client"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (React docs); MIT (Next.js docs); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: React hydration mismatches"
tags: [react, hydration, hydrateRoot, nextjs, ssr, suppressHydrationWarning]
client: Librarian
sources:
  - id: S1
    title: "hydrateRoot"
    publisher: React docs
    url: https://react.dev/reference/react-dom/client/hydrateRoot
    accessed: 2026-11-19
    license: "CC-BY-4.0"
  - id: S2
    title: "Text content does not match server-rendered HTML"
    publisher: Next.js docs
    url: https://nextjs.org/docs/messages/react-hydration-error
    accessed: 2026-11-19
    license: "MIT"
---
# 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

- [react-effects](https://iinventedlight.com/library/notes/react-effects/)
- [react-conditional-rendering](https://iinventedlight.com/library/notes/react-conditional-rendering/)
- [nextjs-error-handling](https://iinventedlight.com/library/notes/nextjs-error-handling/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
