Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client.
Next.js · updated 2026-11-05
Appears in the browser console and the Next.js dev overlay as the page loads, with a diff of server versus client markup. In production React recovers by re-rendering on the client, so users see a flash and the console logs a minified error.
Error: 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 <time dateTime="2026-10-09T14:03:00Z"> + 10/9/2026, 9:03:00 AM - 10/9/2026, 2:03:00 PM
Quick fix
Render anything that differs between server and browser (Date.now(), Math.random(), window, localStorage, locale-formatted dates) only after mount inside useEffect, or format it with an explicit locale and timeZone on both sides. For a single unavoidable mismatch like a timestamp, add suppressHydrationWarning to that element.
- Read the diff in the dev overlay: + lines are client values, - lines are server values.
- Move window, localStorage and Date.now() reads into useEffect with useState.
- Format dates with a fixed locale and timeZone, or format them only on the client.
- Fix invalid nesting such as a <div> inside a <p> or an <a> inside an <a>.
- Reload in a private window with extensions off to rule them out.
- Use suppressHydrationWarning only on the one element whose text must differ.
'use client';
import { useEffect, useState } from 'react';
export function LocalTime({ iso }: { iso: string }) {
const [text, setText] = useState<string | null>(null);
useEffect(() => {
// Runs only in the browser, after hydration, so the first render matches the server
setText(new Date(iso).toLocaleString());
}, [iso]);
return <time dateTime={iso}>{text ?? iso}</time>;
}Paste this into Claude Code, Cursor or Codex in the project that throws it. The agent reads this guide in plain text and applies the fix that matches your stack.
Read https://runheed.com/errors/hydration-mismatch.md and fix this error in this project.Why it happens
Browser-only branches during render
typeof window !== 'undefined' checks, localStorage reads and matchMedia calls give one result on the server and another in the browser. The first client render must match the server HTML, so these reads belong in an effect.
Time and randomness
Date.now(), new Date() and Math.random() return different values in the two renders. A relative label like '3 minutes ago' can also flip between server and client when the minute rolls over.
Locale and time zone formatting
toLocaleString() with no arguments uses the server's locale and time zone (often en-US and UTC in containers) on the server, then the visitor's settings in the browser. Pass a fixed locale and timeZone, or format on the client.
Invalid HTML nesting
The browser's HTML parser repairs invalid markup before React hydrates: a <div> inside a <p> closes the paragraph early and nested <a> tags get split apart. React then finds a different DOM tree than the one it rendered.
Browser extensions editing the page
Password managers, translators and grammar tools inject attributes or nodes into <html>, <body> or form fields before React loads. These mismatches only appear for visitors with that extension, which is why they are hard to reproduce.
Data that changed between the two renders
The server renders with one API response and the client fetches again during its first render and gets newer data. Pass the server snapshot down as props instead of refetching before hydration finishes.
Other fixes
- Load a component that cannot render on the server with next/dynamic and ssr: false from inside a client component.
- Add suppressHydrationWarning to <html> and <body> in the root layout when theme scripts or extensions change their attributes.
- Read browser stores through useSyncExternalStore with a getServerSnapshot so server and first client render agree.
- Generate element ids with useId instead of a random id helper.
Same error, other wording
- Error: Hydration failed because the initial UI does not match what was rendered on the server.
- Warning: Text content did not match. Server: "x" Client: "y"
- Minified React error #418
- A tree hydrated but some attributes of the server rendered HTML didn't match the client properties. This won't be patched up.
Let your coding agent catch the next one
This error happens in the browser. Runheed records it when your frontend reports through @sentry/browser or @sentry/react with a Runheed DSN (setup), with your source lines when the bundle has a source map, and serves it to Claude Code, Cursor or any MCP client.
Setup for Next.js, React and browser JavaScript or Vercel Functions, then have your agent fix and resolve it.
Related errors
- An error occurred in the Server Components render. The specific message is omitted in...
- Dynamic server usage: Route /x couldn't be rendered statically because it used `headers`.
- Module not found: Can't resolve 'fs'
More in React and Next.js rendering
- ResizeObserver loop completed with undelivered notifications.Browser
- ReferenceError: window is not definedNext.js
- Error: Event handlers cannot be passed to Client Component props.Next.js
- Only plain objects, and a few built-ins, can be passed to Client Components from Server...Next.js
- Route "/orders/[id]" used `params.id`. `params` should be awaited before using its...Next.js
- Error: NEXT_REDIRECTNext.js
- Error: NextRouter was not mounted.Next.js
- Invalid src prop (https://cdn.example.com/p/42.jpg) on `next/image`, hostname...Next.js
- TypeError: Failed to parse URL from /api/ordersNext.js
- Too many re-renders. React limits the number of renders to prevent an infinite loop.Next.js
- useSearchParams() should be wrapped in a suspense boundary at page "/search".Next.js
- You're importing a module that depends on `useState` into a React Server Component...Next.js
- Objects are not valid as a React child (found: object with keys {id, name, total}). If...Next.js
- Element type is invalid: expected a string (for built-in components) or a class/function...Next.js
- Failed to find Server Action "7f3a9c2e5d1b4a6f8c0e2d7b9a1c3e5f7d9b0a2c4e". This request...Next.js
- ChunkLoadError: Loading chunk 4512 failed. (error...Next.js
Other error topics
- Error: read ECONNRESETNetwork and HTTP
- Access to fetch at 'https://api.example.com/orders' from origin 'https://app.example.com'...Network and HTTP
- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer...Network and HTTP
- error: infinite recursion detected in policy for relation "members"Databases
- pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection...Databases
- django.db.utils.OperationalError: no such table: orders_orderDatabases
- ImportError: libGL.so.1: cannot open shared object file: No such file or directoryImports and modules
- Error: Cannot find module 'x'Imports and modules
- ImportError: cannot import name 'x' from partially initialized module 'y' (most likely...Imports and modules
- System.InvalidOperationException: Sequence contains no elementsUndefined, None and type errors
- TypeError: Client is not a constructorUndefined, None and type errors
- TypeError: unsupported operand type(s) for +: 'int' and 'str'Undefined, None and type errors
- pydantic_core._pydantic_core.ValidationError: 1 validation error for User email Field...JSON, parsing and validation
- SyntaxError: Unexpected end of JSON inputJSON, parsing and validation
- RangeError: Invalid time valueJSON, parsing and validation
- OSError: [Errno 98] Address already in useMemory, async and the process
- PermissionError: [Errno 13] Permission denied: '/app/data/report.csv'Memory, async and the process
- RangeError: Maximum call stack size exceededMemory, async and the process
- Bad Request: Unsupported protocol version: 2026-07-28MCP servers and clients
- MCP error -32602: Input validation error: Invalid arguments for tool get_orderMCP servers and clients
- Not Acceptable: Client must accept both application/json and text/event-streamMCP servers and clients
Free tools: Source map stack trace decoder · Uptime and SLA downtime calculator · Error budget calculator · Stack trace formatter · JSON log viewer · HTTP status code reference.
References: Next.js: Text content does not match server-rendered HTML, React: hydrateRoot
Spotted a mistake? Email hello@greatwork.company. About Runheed.