Next.js Hydration Error: What Each Message Means and How to Fix It
A hydration error means the server’s HTML and React’s first render in the browser differ. One project was run on Next.js 14, 15 and 16 to record the message each cause prints, how much of the page React throws away, what a production build shows instead, and which fix removes the error without hiding it.
Ali RehmanFreelance Web Developer
On this page 15 sections
The page loads, and then a red overlay or a line in the console says that the server and the client did not match. That is a hydration error. The sentence is the same for a dozen different mistakes, so it rarely tells you which line to change. The wording around it does, and this guide starts there.
window or localStorage. “The server rendered HTML didn’t match the client” means an element differs: invalid nesting, or something inserted into the page. “A tree hydrated but some attributes… didn’t match” means an attribute differs. Read the two diff lines under the message, then make both renders produce the same output, or move the browser-only value out of the first render.The results in this guide were measured. A test App Router project was run on 28 November 2026 on three releases: Next.js 16.3.5, 15.5.29 and 14.2.35, with 59 recorded checks. Each of its pages either caused one kind of mismatch or prevented one. The final section gives the method and the limits. Only the App Router is covered.
Find your message first
Match what the console shows to a section. Sections 1 to 6 use the wording of Next.js 15 and 16. If your project is on Next.js 14, start at section 7 and come back.
What the console says
→ section
"... the server rendered text didn't
match the client"
→ 1 and 2
"... the server rendered HTML didn't
match the client"
→ 3, or 5 if you did not write
the element
"In HTML, <div> cannot be a
descendant of <p>"
→ 3
"A tree hydrated but some attributes
... didn't match"
→ 4
An attribute on <body> or <html>
that is not in your code
→ 5
"Minified React error #418"
→ 6
"Text content does not match
server-rendered HTML" or "the initial
UI does not match"
→ 7What hydration is, and why Server Components are different
Next.js renders a page to HTML on the server, so the browser can show it before any JavaScript has run. React then loads, renders the same components again in the browser and attaches its event handlers to the elements that are already on the page. That second step is hydration. React’s reference for hydrateRoot gives the rule in one sentence: the tree React renders in the browser needs to produce the same output as it did on the server.
Client Components are rendered in both places, so they are where a value can come out differently. A Server Component runs on the server only, and the browser receives its result. In the test, a Server Component that printed Date.now() produced no message: the browser kept the number the server had sent. The same call inside a Client Component raised the error in development and in production. So the first question for any value in the diff is which kind of component renders it. Markup is the exception. Invalid nesting fails in a Server Component too, as section 3 shows.
When the two renders differ, React does not stop. The same reference page says that React recovers from some hydration errors, that they still have to be fixed like other bugs, and that the best case is a slowdown while the worst case is event handlers attached to the wrong elements. In the test, every failing page still answered 200, finished loading and responded to a button press afterwards. What changed was how much of the page React threw away.
How much of the page React rebuilds
The message ends with “this tree will be regenerated on the client”. The test measured which tree. A small script marked every element the server had sent before React started. After hydration, an element without the mark was a new one that React had created in the browser.
- No Suspense boundary above the mismatch: React rebuilt everything inside
body. That included the paragraph with the wrong text, its sibling, the page’smainelement, and the header and the button that belonged to the root layout. Onlyhtmlandbodywere kept. - A Suspense boundary around the component: only the element inside the boundary was rebuilt. Its sibling, the page and the layout were kept.
- A
loading.tsxfile in the route folder: the page’s elements were rebuilt, and the layout’s header and button were kept.
The third result follows from how Next.js uses that file: the loading file reference says it wraps the page in a Suspense boundary. The first two results were the same in development and in production on all three versions. The loading.tsx case was run on 15.5.29 and 16.3.5.
This is the part that is easy to miss. One wrong timestamp in a footer can make the browser discard a whole server-rendered page and build it again. Nothing looks broken, so the error gets ignored, but the visitor’s device did the work twice. If load time matters on the site, treat it like any other item in Next.js performance work.

1. Text didn’t match: typeof window, localStorage and browser checks
This is the message on 15.5.29 and 16.3.5 in development when a piece of text differs. The explanation in the middle is the same for every cause, so it is shortened here. The last two lines are the ones to read.
Hydration failed because the server rendered
text didn't match the client. As a result this
tree will be regenerated on the client.
...
+ client text
- server textThe line after + is what the browser rendered. The line after - is what the server sent. A branch on typeof window is the most direct way to get there, because it asks for a different result on each side on purpose:
"use client";
export default function Where() {
// Server: "server text". Browser: "client text".
return (
<p>
{typeof window === "undefined"
? "server text"
: "client text"}
</p>
);
}The localStorage version is the same mistake in a form that looks reasonable:
"use client";
import { useState } from "react";
export default function Theme() {
const [theme] = useState(() =>
typeof window === "undefined"
? "light"
: localStorage.getItem("theme") ?? "light",
);
return <p>{theme}</p>;
}With dark stored in the browser, the server sent light, the diff read + dark and - light, and React rebuilt the page. The guard itself is needed. Without it the server stops with a different error, covered in window is not defined in Next.js. But the guard only moves the problem from the server to hydration. The first render in the browser has to return what the server returned, and the stored value has to arrive after that. The section on fixes shows three ways to do it.
An element that exists only in the browser, such as {typeof window !== "undefined" && <span>…</span>}, produced the HTML message from section 3 instead, with the extra element after +.
2. Text didn’t match: dates, time zones and random values
A date is the same instant everywhere. Its text depends on the time zone and the locale of whoever formats it.
"use client";
export default function EventTime() {
const date = new Date("2026-06-15T22:30:00Z");
return <p>{date.toLocaleString("en-US")}</p>;
}In the test the server ran in UTC and the browser was set to Asia/Karachi. The server sent 6/15/2026, 10:30:00 PM. The browser rendered 6/16/2026, 3:30:00 AM. Hydration failed in development and in production.
This is the version that passes on a developer’s machine and fails for visitors. When the dev server and the browser run on the same computer, they share a time zone and a locale, and the two strings are equal. The Next.js guide on preventing flash before hydration recommends starting the dev server with TZ and LANG set differently from the browser, and calls TZ=UTC a good default because most servers run in UTC. The test did this on Windows, and Node.js honoured it.
# macOS and Linux
TZ=UTC npx next dev
# Windows PowerShell
$env:TZ = "UTC"; npx next devPassing a fixed zone, toLocaleString("en-US", { timeZone: "UTC" }), gave the same text on both sides and no message. Showing the visitor’s own local time needs one of the techniques in the fixes section.
Date.now() and Math.random() fail for a simpler reason: every call returns a new value. Both produced the text message in a Client Component, with two different numbers in the diff. For an id that connects a label to an input, use React’s useId: the page that linked the two with it printed nothing. Its reference adds one condition: the component tree has to be identical on the server and the client.
3. HTML didn’t match: invalid nesting
When an element differs instead of a piece of text, one word in the message changes: “Hydration failed because the server rendered HTML didn’t match the client.” In development React prints a second line before it, and that line is the useful one:
In HTML, <div> cannot be a descendant of <p>.
This will cause a hydration error.The test produced three of these hints on 15.5.29 and 16.3.5:
- A
divinside ap: the hint above. - A link inside a link: “In HTML, <a> cannot be a descendant of <a>.”
- A
trdirectly inside atable: “In HTML, <tr> cannot be a child of <table>. Add a <tbody>, <thead> or <tfoot> to your code to match the DOM tree generated by the browser.”
The cause is the browser’s HTML parser, not React. A paragraph may contain only phrasing content, and its end tag is implied as soon as a div follows; both rules are on MDN’s page for the p element. The server sent <p>before <div>block</div> after</p>. Before React started, the paragraph in the browser held only the word “before”: the parser had already closed it in front of the div. React then compared its own tree with a page that had a different shape.
Two details from the test matter here. The same failure happened in a Server Component on a page with no client code at all, so "use client" is not a condition for this error. And a production build prints no hint, only the code from section 6.
The fix is in the markup, and no React API replaces it. Change the outer p to a div, or the inner block to a span. Keep one link per card. Put table rows inside tbody. The usual sources are a CMS or Markdown renderer that wraps a block component in a paragraph, and a card that is itself a link and also contains one.
One case did not reproduce. A nested layout that returned html and body a second time printed nothing on 15.5.29 and 16.3.5, and the document still had one of each. Other arrangements of that mistake were not tested.
4. Attributes didn’t match: the message that is not an error
A tree hydrated but some attributes of the
server rendered HTML didn't match the client
properties. This won't be patched up.
...
+ className="from-client"
- className="from-server"This message looks like the others and behaves differently in three ways, each recorded in the test:
- It is written with
console.errorand nothing is thrown. No element was rebuilt. - The element keeps the server’s value. The class was still
from-serverafter hydration on all three versions. - A production build prints nothing for it. Not a code, not a warning.
So an attribute mismatch is silent for visitors and still wrong: the page shows what the server chose while React holds a different value. The hydrateRoot reference says the same in general terms, that there are no guarantees attribute differences will be patched up. If a class, a style or an href depends on something only the browser knows, development is the only place you will be told.
The common real case is a theme script. A short inline script in head reads the saved theme and sets an attribute on html before the first paint, which is the pattern the Next.js guide linked in section 2 uses. In the test, with dark stored, the diff was + data-theme="light" and - data-theme="dark", and the attribute stayed dark. Adding suppressHydrationWarning to the html element removed the message, and the attribute still stayed dark in development and in production.
const themeScript = `(function () {
try {
var root = document.documentElement;
var theme = localStorage.getItem("theme");
if (theme) {
root.setAttribute("data-theme", theme);
}
} catch (error) {}
})()`;
const inline = { __html: themeScript };
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html
lang="en"
data-theme="light"
suppressHydrationWarning
>
<head>
<script dangerouslySetInnerHTML={inline} />
</head>
<body>{children}</body>
</html>
);
}On 16.3.5 the development overlay also separates the two kinds. It labelled a failed hydration “Recoverable Error” and the attributes message “Console Error”.
5. Browser extensions: which changes matter
The error text itself says a browser extension can be the cause. The test simulated what extensions do with a script that changed the page before React started. No real extension was installed, so read the results as what React does with each kind of change, not as a statement about a particular product.
- An attribute added to
bodyorhtml(the test useddata-gr-ext-installedanddata-darkreader-mode): the attributes message from section 4 in development, with the attribute after-. Nothing in production. Nothing was rebuilt and the attribute stayed. - An element appended to the end of
body, and astyleelement added tohead: no message on any of the three versions. Both were still there after hydration. - An element inserted between the page’s own elements: the HTML mismatch error. React rebuilt the page, and the inserted element was gone afterwards.
- Text replaced, the way a translation tool does it: the text mismatch error, and React put its own text back.
The second result matches the React 19 release notes, which say that unexpected tags in head and body are skipped during hydration. The third and fourth are outside your control: your code is correct and that visitor still gets a rebuild.
To check, load the page in a private window where extensions are disabled. If the message is gone, it came from an extension. If it is still there, it is yours. An extension that only tags body explains a development-only attributes message and nothing more. Adding suppressHydrationWarning to body for that reason hides a message about body’s own attributes; as the section on that attribute shows, it does not reach the elements inside.
6. Only in production: Minified React error #418
A production build does not print any of the sentences above. On 15.5.29 and 16.3.5 every failing page logged exactly one error:
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.The part to read is args[]=. With text, a value differs: sections 1 and 2. With HTML, an element differs: section 3, or an inserted element from section 5. The React page behind the link shows the full sentence with that word filled in.
Production leaves out the diff, the component names, the nesting hint and every attributes message. The outcome was otherwise the same: on every page, production rebuilt the same elements as development.
To find the value, reproduce the error where the full message exists, which is next dev. If it appears only on the live site, something outside the code differs between the two environments: the server’s time zone or locale, a value stored in your own browser, an extension, or HTML that was changed on its way to the browser.
The last of those was tested by editing the HTML response before the browser received it, as an HTML-rewriting proxy or CDN feature would. The component rendered the same email address on both sides, and the edited response carried a placeholder in its place. The result was the text mismatch error, a rebuild of the page, and React restoring the address. The Next.js page for this error lists that cause as an incorrectly configured Edge or CDN that modifies the HTML response. It also describes iOS turning phone numbers, email addresses and other data in text into links, with a format-detection meta tag that switches the behaviour off. Neither a real CDN nor iOS was part of this test.
7. Next.js 14 and React 18: the older messages
A project on Next.js 14 sees different words for the same events, and the reason is not the react version in package.json. The App Router renders with the React build that ships inside Next.js. In the test the installed package was 19.2.4 in the two newer projects and 18.3.1 in the old one, while the version React reported in the browser was a 19.3 canary on 16.3.5, a 19.2 canary on 15.5.29 and an 18.3 canary on 14.2.35. The Next.js version decides the wording.
Next.js 14.2.35, development
Text differs
Warning: Text content did not match.
Server: "server text" Client: "client text"
Text content does not match
server-rendered HTML.
Element differs
Warning: Expected server HTML to contain
a matching <span> in <div>.
Hydration failed because the initial UI
does not match what was rendered on the
server.
Attribute differs
Warning: Prop `className` did not match.
Server: "from-server" Client: "from-client"
Attribute added to <body>
Warning: Extra attributes from the server:
data-gr-ext-installedBoth errors came with “An error occurred during hydration. The server HTML was replaced with client content in <#document>.” Inside a Suspense boundary that line was replaced by “There was an error while hydrating this Suspense boundary. Switched to client rendering.”
In production on 14.2.35 a text mismatch logged three codes, #425, #418 and #423, and an element mismatch logged #418 and #423, without the args that the newer versions add. Inside a Suspense boundary the codes were #425 and #422. The behaviour matched the newer versions: the same elements were rebuilt, and the page ended with the browser’s text. If you search for one of the old sentences and land on advice written for React 19, the causes and the fixes still apply.
Which fix for which case
Fix the cause when there is one to fix: valid markup, a fixed time zone, a value the server can know. When a value exists only in the browser, these are the options, with what each one did in the test.
Let the server read it: a cookie instead of localStorage
A setting kept in a cookie travels with the request, so the server can render the right version from the start. The server rendered dark, the browser agreed, and nothing was printed.
import { cookies } from "next/headers";
export default async function Page() {
const store = await cookies();
const saved = store.get("theme")?.value;
const theme = saved ?? "light";
return <p>{theme}</p>;
}The cost is that cookies() makes the page render on each request. The build listed this page as dynamic, while the localStorage and useEffect pages were static. The await matters as well; leaving it out breaks on Next.js 16, as described in params should be awaited.
Set it after hydration with useEffect
"use client";
import { useEffect, useState } from "react";
export default function Theme() {
const [theme, setTheme] = useState("light");
useEffect(() => {
const saved = localStorage.getItem("theme");
setTheme(saved ?? "light");
}, []);
return <p>{theme}</p>;
}An effect never runs on the server and runs in the browser only after hydration, so the first render matches. In the test this pattern, with fixed values in place of localStorage, printed nothing on any of the three versions and nothing was rebuilt. The visitor sees the server’s value first and the real one a moment later. The hydrateRoot reference describes the same two-pass approach and warns that it makes hydration slower, because the component renders twice.
Give React a server snapshot with useSyncExternalStore
"use client";
import { useSyncExternalStore } from "react";
function subscribe(notify: () => void) {
window.addEventListener("storage", notify);
return () =>
window.removeEventListener("storage", notify);
}
export default function Theme() {
const theme = useSyncExternalStore(
subscribe,
() => localStorage.getItem("theme") ?? "light",
() => "light", // server render and hydration
);
return <p>{theme}</p>;
}The third argument is the server snapshot. React’s reference for useSyncExternalStore says it is used during server rendering and during hydration, and that it must be the same on both sides. In the test, again with fixed values, the server’s text was hydrated without a message and then replaced by the browser’s value, and nothing was rebuilt.
Skip server rendering for one component
"use client";
import dynamic from "next/dynamic";
const Map = dynamic(() => import("./map"), {
ssr: false,
loading: () => <p>Loading map…</p>,
});
export default function Location() {
return <Map />;
}The server’s HTML held the loading placeholder and not the component. The component appeared in the browser with no message, and the rest of the page was kept. Its content is therefore missing from the HTML the server sends, so this suits a map or a chart and not text that belongs in the page source.
The option has to be used from a Client Component, as the lazy loading guide says. In a Server Component the build stopped on 15.5.29 and 16.3.5 with this error. On 14.2.35 the same file built without one; what it did at runtime there was not checked.
`ssr: false` is not allowed with `next/dynamic`
in Server Components. Please move it into a
Client Component.Correct it before the first paint with an inline script
For a date in the visitor’s own time zone with no visible swap, the Next.js guide from section 2 places a small script directly after the element and marks the element with suppressHydrationWarning. The browser runs the script while it is still reading the HTML.
export default function Page() {
const iso = "2026-06-15T22:30:00Z";
const fix =
`document.getElementById("when").textContent=` +
`new Date("${iso}").toLocaleString("en-US")`;
return (
<>
<p id="when" suppressHydrationWarning>
{new Date(iso).toLocaleString("en-US")}
</p>
<script
dangerouslySetInnerHTML={{ __html: fix }}
/>
</>
);
}In the test the server sent 10:30 PM, the script had changed the text to 3:30 AM before React started, React printed nothing, and 3:30 AM stayed. One more page in the same test is a warning. It had this corrected date and, elsewhere on the page, a component with an unrelated mismatch and no Suspense boundary. React rebuilt the page and the date went back to 10:30 PM. The guide states the rule: corrections inside a boundary that React rebuilds are lost. The technique depends on the rest of the page hydrating cleanly. The guide also covers client-side navigation, which this test did not.

What suppressHydrationWarning does and does not do
React’s reference for common component props describes it as an escape hatch that works one level deep. The test checked four placements on 15.5.29 and 16.3.5:
- On the element whose own text differs: no message, and the server’s text stayed on screen. React did not replace it with the browser’s value.
- On the parent of that element: no effect. The error was raised and the page was rebuilt.
- On an element whose attribute differs: the attributes message was gone, and the element still kept the server’s attribute.
- On an element with a child that exists only in the browser: no effect. The HTML mismatch error was raised.
It never repairs anything. It tells React that a difference in that one element’s own text or attributes is expected, and whatever the server sent remains. That fits the html element with a theme script, or one timestamp that a script has already corrected. Anywhere else it leaves a bug in place and removes the only message that reported it.
How to find the mismatch, step by step
- 1Run
next dev, open the page and read the two diff lines under the message:+is the browser,-is the server. On 16.3.5 the message is repeated in the terminal with a[browser]prefix. On 15.5.29 it appeared only in the browser. - 2Read the word after “server rendered”: text, HTML, or the attributes sentence. That selects the section above.
- 3Load the page in a private window that has no extensions enabled. If the message disappears, an extension caused it.
- 4For an HTML mismatch, compare View Source with the Elements panel. View Source is what the server sent, and Elements is what the browser built from it. A paragraph that closes early is invalid nesting.
- 5Start the dev server with
TZ=UTC, and store a non-default value for anything the page keeps inlocalStorage. A developer’s machine hides both bugs. - 6If only production fails, read
args[]in error #418, then look at what sits between the server and the browser. - 7While you look for the cause, a Suspense boundary around the suspect component limits the rebuild to that component. That contains the damage. It is not a fix.
If the project is one you inherited and none of these steps finds the cause, tracing it is part of my Next.js development work. Use the contact page and include the page address and the full message. For anyone picking a developer to maintain the application instead, how to hire a Next.js developer covers the questions worth asking.
Frequently asked questions
What is a hydration error in Next.js?
It is React reporting that the HTML rendered on the server differs from what the same components rendered first in the browser. Client Components run in both places, so a value that depends on the time, the time zone, randomness or browser storage can differ. Invalid HTML nesting causes it too, in any kind of component.
Can I ignore a hydration error if the page works?
The page does keep working. In the test every failing page loaded and stayed interactive. But without a Suspense boundary React rebuilt everything inside body, which wastes the server render, and an attribute mismatch left the server’s value in place with no message in production. Fix it.
Why is there a hydration error only in production?
Something differs between your machine and the live site. The usual candidates are the server’s time zone and locale, HTML changed between the server and the browser, and extensions or stored values in a visitor’s browser. Production shows only Minified React error #418, so reproduce it in development with TZ=UTC to see the diff.
What does Minified React error #418 mean?
It is the production form of “Hydration failed because the server rendered text or HTML didn’t match the client”. On Next.js 15 and 16 the address in the message ends with args[]=text or args[]=HTML, which tells you whether a value or an element differs. On Next.js 14 it appeared together with #425 and #423.
How do I fix a hydration error caused by localStorage?
Do not read it during the first render. Render the default the server used, then read the stored value in useEffect, or use useSyncExternalStore with a server snapshot. To avoid the visible switch, keep the setting in a cookie so the server can read it, or set an attribute from an inline script before the first paint.
Should I add suppressHydrationWarning to html or body?
On html it is the documented choice when a script sets a theme attribute before React loads. In the test it removed the message and kept the script’s value. It covers only that element’s own attributes and text, so it does not hide mismatches further down the page, and it does not fix them either.
Sources, test and review scope
Where a sentence above says what the documentation states, the page is linked at that point. All of them were read on 28 and 29 November 2026: the Next.js page for the hydration error, the guides on preventing flash before hydration and on lazy loading, and the references for the loading file and cookies(); React’s references for hydrateRoot, common component props, useSyncExternalStore and useId, the React 19 release notes and the page for error 418; and MDN’s reference for the p element. The error messages, quoted in the text or set in code blocks, are the ones the test recorded. Long lines are wrapped, and the repeated list of possible causes inside the message is left out.
The test project is a TypeScript App Router application with one page per case. Three copies were installed from the npm registry into separate folders: Next.js 16.3.5 and 15.5.29 with React 19.2.4, and Next.js 14.2.35 with React 18.3.1, on Node.js 24.12. Each version ran in development with next dev and as a production build with next start; 16.3.5 built with Turbopack and the other two with webpack. The server ran in UTC and the browser, headless Microsoft Edge with a fresh profile for every visit, was set to Asia/Karachi. Each page was first requested without a browser to read the HTML the server sent. In the browser, a script in the layout marked the server’s elements before React started, so the run could tell afterwards which elements had been kept, and a button in the layout was pressed to confirm the page still responded. On 16.3.5 that marker script caused one extra development notice about script tags whenever React rebuilt the page; it is not part of the results above.
The run made 178 page visits, 37 pages in each mode on 16.3.5 and 15.5.29 and 15 core pages on 14.2.35, built the project 6 times, and checked 59 expectations against the recorded output. All 59 held. The seven that carry this guide:
- 1Five kinds of differing text raised the text message on 15.5.29 and 16.3.5, with the browser’s value after
+and the server’s after-. - 2Invalid nesting raised the HTML message, with a hint naming the two elements in development only, in Client and Server Components alike.
- 3A differing attribute was logged in development, never corrected, and silent in production on all three versions.
- 4Without a Suspense boundary React rebuilt everything inside
body; with one, only its contents. - 5Production on 15.5.29 and 16.3.5 logged one Minified React error #418 per failing page, with
args[]=textorargs[]=HTML. - 6On 14.2.35 the same mismatches used the older wording and the codes #425, #418, #423 and #422.
- 7An effect, a server snapshot, a cookie, a fixed time zone,
ssr: falseand an inline script each removed the error;suppressHydrationWarningremoved only the message.
What this cannot tell you: the whole run happened on a single Windows machine, served by the Node.js server built into Next.js, in one Chromium-based browser. Outside the test: Vercel and other hosts, a real CDN, real browser extensions, Safari and iOS, Firefox, the Pages Router, CSS-in-JS and component libraries, React Compiler, Cache Components, and every Next.js release other than the three installed. Extensions and the edited response were simulated with scripts. The pages were small synthetic examples, and a larger application can add causes that are not listed here. AI tools assisted with the research and ran the test; the recorded results were then compared with the linked documentation before publishing.
Written by
Ali Rehman - Freelance Web Developer
I work on WordPress websites, practical fixes and scoped web applications. Read my background and skill scope, or send a project brief to discuss a written plan and quote - start here.
More articles by Ali Rehman →