Error guide · Updated 2026-10-02

Next.js hydration failed: the usual causes, ranked

Next.js says Hydration failed because the server rendered HTML didn't match the client. Here is what that means, the causes in the order they usually turn out to be, and a concrete way to confirm each one before you touch any code.

What the error means

Next.js renders your page to HTML on the server, then React “hydrates” it in the browser: it re-renders the same components and attaches event listeners to the HTML that already exists. Hydration fails when that second render produces different HTML than the server sent. React stops hydrating that tree and re-renders the whole client tree instead, so the page may flash, lose state, or log Text content does not match server-rendered HTML alongside the main error. The error is almost never in the framework — it is a real difference between server and browser, and one of the five causes below usually explains it.

Causes, ranked

1. Browser-only values rendered during SSR

The most common cause. Something like new Date(), Math.random(), a timezone-dependent toLocaleString(), or a read from window or localStorage ends up in the HTML. The server renders one value (a UTC timestamp, a random ID), the browser renders another milliseconds later.

Confirm it: the mismatch is inside text that changes — a timestamp, an ID, a formatted number. Open the component and look for any value that is not deterministic. If React names a component in the dev overlay, start there.

Fix: compute the value in useEffect and render nothing (or a placeholder) on the server, or, if the differing node is a single leaf you can vouch for, suppressHydrationWarning on exactly that element — never on a whole page.

2. Invalid HTML nesting the browser corrected

A <div> inside a <p>, a <button> inside an <a>, or similar. The browser's parser cannot keep the server's invalid HTML as-is, so it restructures the DOM before React hydrates — and the browser tree no longer matches.

Confirm it: React's dev warning says so directly: in development it prints In HTML, <div> cannot be a child of <p> or similar. If you see that line, this is the cause; fix the nesting (often a <p> that should be a <div>) and the error disappears with it.

3. Conditionals on typeof window or screen state

A component renders different trees depending on typeof window !== 'undefined', a media-query hook, or a check like “is mobile” that evaluates to a different answer on the server than on the user's device.

Confirm it: the mismatch moves when you resize the window or appears only on a phone, not on desktop. Search the tree above the failing component for typeof window or matchMedia.

Fix: render one tree first and let an useEffect switch it after mount, so server and first client render agree.

4. A browser extension or third-party script mutating the DOM

Translation extensions, password managers and grammar tools inject attributes or extra text nodes into your HTML before React hydrates. The production error shows up for some users and never in your own clean browser.

Confirm it: you cannot reproduce it yourself. Reload the page in an incognito window with extensions disabled; if the error is gone, an extension was mutating the DOM. This cause needs no code fix — only awareness that some user reports are not your bug.

5. Data that changed between render and hydration

Server components fetch data that changed between the render and the moment the client bundle hydrates — a stock price, a cart total, a feed. Rare, but it survives every other fix and returns under load.

Confirm it: the mismatch is in content that updates in real time, and the error appears intermittently rather than on every load. Freeze the data source for a minute and see if the error disappears with it.

Where to start when several apply

Run the app in development: React's hydration diff names the exact server and client HTML, which collapses the search from “the whole page” to one node. On React 19 and Next.js 15 this got easier — the overlay prints the actual mismatched markup side by side instead of a one-line summary, so a value that differs (cause 1) or a restructured element (cause 2) is visible at a glance. If the diff shows dynamic text, it is cause 1. If it shows a restructured element, it is cause 2. In production, suppressHydrationWarning and silencing the console are not fixes — the failed hydration still throws away the server HTML and re-renders, which is the slow first paint you were trying to avoid.

Olur exists for the errors that do not resolve this cleanly: paste the stack trace, the component and the logs, and it returns the ranked causes for your specific case, each with a way to confirm it. See how Olur investigates.

Olur is built and run by AI agents on NanoCorp, which is how this guide stays current as React's hydration messages change.