Skip to content

Troubleshooting guide

React hydration error: causes and how to fix it

React rendered HTML on the server and then found that the browser's first render was different. Non-deterministic rendering and invalid HTML are the two usual causes.

3 min read10 sectionsUpdated

On this page

Key points

  • First client render must equal the server HTML.
  • Dates and random values commonly differ.
  • Invalid nesting, such as a div inside a p, gets rewritten by browsers.
  • Mismatches can hurt performance by forcing client rendering.

What it means

Hydration attaches React to existing server HTML. If the trees differ, React reports a mismatch and may discard the server HTML for that boundary and re-render on the client, which costs time and can cause a layout shift.

Common causes

  • Date.now(), Math.random() or locale formatting during render.
  • window or localStorage checks producing different output.
  • Invalid HTML nesting, which browsers auto-correct.
  • Browser extensions injecting nodes.
  • CDN or proxy HTML rewriting, like email obfuscation features.

Diagnose it

The development build shows a diff. To reproduce a production issue, compare the raw HTML with what the page holds after hydration.

bash
# HTML as the server sent it
curl -s https://example.com/page > /tmp/server.html

# Common invalid nesting to look for in that HTML
grep -oE '<p[^>]*>[^<]*<div' /tmp/server.html | head

# Check for proxy rewriting of the page
curl -sI https://example.com/page | grep -iE 'server|cf-'
grep -c 'email-decode' /tmp/server.html

Fixes

Render time-dependent values in useEffect, after the first render. Use a fixed locale and time zone when formatting on both sides. Fix nesting, such as a block element inside a paragraph. Use useId rather than random IDs. For truly client-only components, use dynamic import with ssr: false. Use suppressHydrationWarning only on one element where a difference is known and harmless, such as a timestamp.

Why the error appears only in production

Proxies and CDNs are the classic reason. A feature that rewrites HTML on its way to the browser, such as email address obfuscation or automatic minification, changes the markup after React produced it. Local testing has none of those, so the bug appears only on the live site. Browser extensions create mismatches too, which is why errors reported from real users often include some you cannot reproduce. Test in a clean private window first, and compare the raw response before you start changing components.

Catch it automatically

Hydration errors appear only in real browsers, so real-user monitoring is the natural tool: it captures them with the page and browser. React performance monitoring covers the rest.

Frequently asked questions

Does a hydration error break the page?

Often it recovers by re-rendering on the client, but that costs performance.

Should I use suppressHydrationWarning everywhere?

No. It only applies one level deep and can hide real bugs.

Can a browser extension cause it?

Yes. Test in a private window with extensions off.

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.