A React hydration error means the HTML your server rendered is different from what React produced during the first render in the browser, so React throws away that part of the server HTML and re-renders it on the client. The usual culprits are values that differ between server and browser (dates, locales, Math.random(), localStorage), typeof window branches, and invalid HTML nesting such as a <div> inside a <p>. The fix is almost never to silence the error: render the same thing on both sides, then switch to browser-only values after hydration with useSyncExternalStore, useEffect, React 19.3's use(browser()), or a client-only component.
Every error message below was reproduced with React 19.3.1 and react-dom 19.3.1, server-rendering with renderToString and hydrating with hydrateRoot in jsdom on Node 24. That setup lets you see the exact text React prints without a framework in the way.
What the React hydration error message says
The full development message in React 19 looks like this. I triggered it with a component that renders a timestamp:
Hydration failed because the server rendered text didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:
- A server/client branch `if (typeof window !== 'undefined')`.
- Variable input such as `Date.now()` or `Math.random()` which changes each time it's called.
- Date formatting in a user's locale which doesn't match the server.
- External changing data without sending a snapshot of it along with the HTML.
- Invalid HTML tag nesting.
It can also happen if the client has a browser extension installed which messes with the HTML before React loaded.
https://react.dev/link/hydration-mismatch
<Text>
<p>
+ Rendered at 10:00:01
- Rendered at 10:00:00
The part people skip is the most useful part: the diff at the bottom. React 19 added these diffs, replacing the vague "Text content did not match" warnings of React 18, as the React 19 release post describes. Lines starting with + are what the client rendered; lines starting with - are what the server sent. The indented tree above them is the component path, so <Text> tells you exactly which component to open.
There are three variants worth recognizing:
| Message starts with | What differs | What React does |
|---|---|---|
Hydration failed because the server rendered text didn't match the client |
Text content | Re-renders that subtree on the client |
Hydration failed because the server rendered HTML didn't match the client |
Element type or structure | Re-renders that subtree on the client |
A tree hydrated but some attributes of the server rendered HTML didn't match the client properties. This won't be patched up. |
An attribute such as className |
Logs it and leaves the server attribute in place |
That last row surprised me the first time. In my attribute-mismatch test, the server rendered class="server", the client wanted className="client", and after hydration the DOM still said class="server". React warns but does not fix attributes, so an attribute mismatch is a visible bug, not just console noise.
In production builds the message is minified. Here is the same text mismatch with NODE_ENV=production:
Minified React error #418; visit https://react.dev/errors/418?args[]=text&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
Error #418 is the hydration mismatch. If you only see it in production monitoring, reproduce in development to get the diff.
Common causes, roughly in order of how often they show up
The Next.js hydration error page and React's own message list the same causes. In the codebases I have debugged, they show up in roughly this order.
1. Dates, times, locales and random values
new Date().toLocaleString(), Intl.DateTimeFormat, Date.now(), Math.random() and crypto.randomUUID() all produce different values on the server and in the browser. The locale case is sneaky because it works on your machine: your dev server and your browser share a locale and time zone, while production servers usually run in UTC. Next.js's guide on preventing flash before hydration suggests running the dev server with a deliberately different locale to catch this early:
TZ=UTC LANG=ja_JP.UTF-8 next dev
For IDs, use React's useId() instead of random values; it produces the same ID on server and client.
2. typeof window and other browser-only branches
function Banner() {
// Server renders <span>, browser renders <div>: guaranteed mismatch.
return typeof window === "undefined" ? <span>server</span> : <div>client</div>;
}
Reading localStorage, window.innerWidth, navigator.language, or a cookie through document.cookie during render has the same effect. This produced the structural variant of the error in my test:
<Branch>
+ <div>
- <span>
3. Invalid HTML nesting
This is the cause that confuses people most, because both sides render identical JSX. The browser's HTML parser is the one that changes it. <p><div>...</div></p> is invalid HTML, so the parser closes the <p> before the <div>, and the DOM React hydrates against no longer matches its tree. React 19 warns about this specifically before the hydration error:
In HTML, <div> cannot be a descendant of <p>.
This will cause a hydration error.
<Nested>
> <p>
> <div>
The usual offenders: <div> or <ul> inside <p>, <p> inside <p>, <a> inside <a>, <button> inside <button>, and table elements without <tbody>. Rich-text and Markdown renderers that wrap output in <p> are a frequent source.
4. Browser extensions and injected scripts
Password managers, Grammarly, translation tools and ad blockers modify the DOM before React hydrates. React 19 improved this: per the release post, unexpected tags in <head> and <body> are skipped during hydration instead of causing a mismatch. Extensions that add attributes to <html> or <body> can still trigger attribute warnings. The quick test is an incognito window with extensions disabled. If the error disappears, it is not your bug, and a scoped suppressHydrationWarning on <body> is reasonable. A related symptom with no hydration error at all, where the page renders but buttons never respond, is often a Content Security Policy blocking the framework's scripts; our Next.js CSP nonce guide explains that trap.
5. CSS-in-JS and CDN rewriting
CSS-in-JS libraries generate class names at render time. If the server and client generate them in a different order, or styles are not collected on the server, class names differ. In the Next.js App Router, follow the library's documented registry setup from the Next.js CSS-in-JS guide. Also check for anything rewriting HTML between your server and the browser: the Next.js docs specifically mention CDN features such as Cloudflare's Auto Minify. On iOS, Safari can turn phone numbers and dates into links, which is fixed with a format-detection meta tag.
How to fix a React hydration error properly
The rule is: the first client render must equal the server render. Anything browser-specific happens after that.
Fix 1: useSyncExternalStore with a server snapshot
For values that come from the browser (time zone, media queries, localStorage, online status), useSyncExternalStore is the cleanest tool, because its third argument is the value to use on the server and during hydration:
import { useSyncExternalStore } from "react";
const subscribe = () => () => {}; // time zone does not change while the page is open
const getClientTz = () => Intl.DateTimeFormat().resolvedOptions().timeZone;
const getServerTz = () => "UTC";
export function TimeZone() {
const tz = useSyncExternalStore(subscribe, getClientTz, getServerTz);
return <p>Time zone: {tz}</p>;
}
In my test the server HTML was <p>Time zone: UTC</p>, hydration completed with no error, and React immediately re-rendered to the browser's value. React uses the server snapshot during hydration precisely so the first render matches. For a value that does change (window width, matchMedia), give subscribe a real event listener.
Fix 2: useEffect for one-off client values
The classic pattern still works and needs no new APIs:
import { useEffect, useState } from "react";
export function LastSeen({ iso }) {
const [label, setLabel] = useState(iso); // same on server and first client render
useEffect(() => {
setLabel(new Date(iso).toLocaleString()); // browser locale, after hydration
}, [iso]);
return <time dateTime={iso}>{label}</time>;
}
The cost is a visible flash: users see the server value, then the client value. For dates, Next.js's guide shows an alternative: render with suppressHydrationWarning and an inline script placed right after the element that rewrites the text before first paint. That avoids the flash at the cost of a small inline script.
Fix 3: use(browser()) in React 19.3
React 19.3, released September 9, 2026, adds a first-class API for components that cannot produce meaningful HTML on the server:
import { Suspense, use } from "react";
import { browser } from "react-dom";
function SavedFilters() {
use(browser()); // suspends on the server, not on the client
const saved = JSON.parse(localStorage.getItem("filters") ?? "[]");
return <ul>{saved.map((f) => <li key={f}>{f}</li>)}</ul>;
}
export function Sidebar() {
return (
<Suspense fallback={<p>Loading saved filters…</p>}>
<SavedFilters />
</Suspense>
);
}
During server rendering, the nearest Suspense fallback goes into the HTML. In the browser, use(browser()) does not suspend, so the component renders normally after hydration. The Next.js docs now recommend this as the first solution. Two cautions: it needs a <Suspense> boundary around it, and wrapping a component in <Suspense> alone does not make it browser-only. Because it is a use call, it can also be conditional, for example only opting out of SSR when no initial data was passed.
Fix 4: next/dynamic with ssr: false
In Next.js, you can skip prerendering for a whole component, as documented in the lazy loading guide:
"use client";
import dynamic from "next/dynamic";
const Chart = dynamic(() => import("./chart"), { ssr: false });
export default function Dashboard() {
return <Chart />;
}
This only works inside a Client Component. In a Server Component, Next.js errors with "ssr: false is not allowed with next/dynamic in Server Components. Please move it into a Client Component." Use this for heavy browser-only widgets (charts, maps, editors), not as a blanket fix, because the component's content is no longer in the server HTML.
Fix 5: suppressHydrationWarning, used narrowly
suppressHydrationWarning is an escape hatch for an element whose text or attributes are intentionally different. Two behaviors from my tests define how far it reaches:
- It does not patch the content. On a
<time suppressHydrationWarning>where the server rendered10:00:00and the client10:00:01, there was no error, and the DOM kept10:00:00. You get the server value until something re-renders it. - It only applies one level deep. Putting it on a parent
<div>did nothing for a mismatched child<span>: React still threw the full hydration error. The Next.js docs say the same.
So use it on the exact element that differs, typically <time>, the inline-script date pattern above, or <html>/<body> for theme classes and extension attributes. Never put it on a layout wrapper hoping to silence everything below.
How to debug a hydration error step by step
- Read the diff. Find the component path and the
+/-lines. Most fixes are obvious once you know which component and which value. - Compare the raw HTML. View the page source (not DevTools Elements, which shows the post-hydration DOM) and search for the text in the diff. If it already looks wrong in the source, the server rendered it; if it looks right in the source but different in DevTools, something changed it before or during hydration.
- Disable JavaScript and reload. What you see is the server HTML as the parser built it. Invalid nesting shows up here as elements in unexpected places.
- Try incognito with extensions off to rule out extensions.
- Run the server with a different
TZandLANGfrom your browser to flush out locale bugs. - Log recoverable errors in production.
hydrateRootaccepts anonRecoverableErrorcallback; send those errors to your monitoring with the URL so you can find which pages mismatch for real users.
hydrateRoot(document.getElementById("root"), <App />, {
onRecoverableError(error, errorInfo) {
reportError({ message: error.message, stack: errorInfo.componentStack, url: location.href });
},
});
In Next.js you do not call hydrateRoot yourself, so rely on the dev overlay and your error-tracking SDK. A code difference checker is handy for comparing the server HTML with the hydrated DOM side by side when the diff is long.
Hydration errors are also a performance problem, not just a console problem: React discards the server HTML for the mismatched subtree and renders it again on the main thread, which hurts responsiveness during load. If you are chasing slow interactions as well, see our guide to fixing INP issues. Framework choice changes where these bugs come from too; our React Router 7 vs Next.js and Server Actions vs tRPC comparisons cover how each renders on the server.
Frequently Asked Questions
Why do I get "Hydration failed because the server rendered HTML didn't match the client"?
Your component rendered a different element structure on the server than in the browser's first render, most often because of a typeof window branch, a browser-only API read during render, or invalid HTML nesting that the browser's parser rewrote. Read the diff under the message to find the component.
Is it safe to ignore a React hydration error?
Not really. For text and structure mismatches React re-renders that subtree on the client, which costs performance and can cause a visible flicker. For attribute mismatches React does not patch the DOM at all, so the page keeps the wrong server value.
Does suppressHydrationWarning fix hydration errors?
It hides the warning for one element's own text and attributes, one level deep, and React keeps the server content rather than patching it. It does not cover child elements, and it does not fix structural mismatches. Use it only where a difference is intentional.
How do I fix hydration errors caused by dates?
Render a stable value on the server (an ISO string or a UTC-formatted date), then switch to the user's locale after hydration with useEffect or useSyncExternalStore. To avoid the flash, use the inline-script pattern from the Next.js docs with suppressHydrationWarning on the date element.
Can browser extensions cause hydration errors?
Yes, by changing the DOM before React hydrates. React 19 skips unexpected tags in <head> and <body>, which removed many of these errors, but extensions that add attributes can still trigger warnings. Test in an incognito window with extensions disabled to confirm.
What is Minified React error #418?
It is the production-build code for a hydration mismatch. Production builds strip the message, so reproduce the page in development mode to see the full error with its component diff.
Conclusion
A React hydration error is React telling you the server and the browser disagree. Find the component from the diff, make the first client render identical to the server render, and move browser-specific values to after hydration with useSyncExternalStore, useEffect, use(browser()) on React 19.3, or a client-only next/dynamic component. Fix nesting bugs at the source, keep suppressHydrationWarning on single elements where the difference is intentional, and log onRecoverableError in production so you find the mismatches your users actually hit.