afterbuild/ops
ERR-HYD/Next.js · React 19
ERR-HYD
Hydration failed because the initial UI does not match what was rendered on the server. Text content did not match.

appears when:Right after page load in production; dev mode shows a softer warning or nothing at all.

Hydration failed because the initial UI does not match what was rendered on the server

The server rendered one string, the client rendered another. React bails out of hydration, the page flashes, interactivity breaks. Three root causes cover nearly every case and each has one real fix — not suppressHydrationWarning.

Last updated 8 August 2026 · 8 min read · By Hyder Shah
Direct answer

A Next.js hydration error in production means the server HTML and the first client render produced different output. The fix is to render a stable value on the server and update it inside useEffect after mount. Date.now(), localStorage, and window-dependent conditionals must move into useEffect or into a component loaded with dynamic(..., { ssr: false }).

How do I fix Next.js hydration error production?

app/components/ThemeToggle.tsx
tsx
01// app/components/ThemeToggle.tsx — stable SSR, real value after mount02"use client";03 04import { useEffect, useState } from "react";05 06export function ThemeToggle() {07  // SSR renders the same thing the first client pass will: "light"08  const [theme, setTheme] = useState<"light" | "dark">("light");09 10  useEffect(() => {11    // Read localStorage only after hydration — no mismatch possible12    const saved = window.localStorage.getItem("theme");13    if (saved === "dark" || saved === "light") setTheme(saved);14  }, []);15 16  return (17    <button18      suppressHydrationWarning19      onClick={() => {20        const next = theme === "light" ? "dark" : "light";21        setTheme(next);22        window.localStorage.setItem("theme", next);23      }}24    >25      {theme}26    </button>27  );28}
Render the stable default on the server, hydrate the real value in useEffect.

Not a developer? We fix this for you at a fixed price: $299 emergency triage, done in 48 hours or fully refunded. Not sure what else is broken? Send the repo for the $49 audit.

What if the quick fix doesn't work?

01 · Dynamic import with ssr: false for browser-only components

Chat widgets, charting libraries that depend on window, anything that reaches for DOM at module load — these should skip SSR entirely.

app/components/ChatWidget.tsx
tsx
01import dynamic from "next/dynamic";02 03const ChatWidget = dynamic(() => import("./chat-widget-impl"), {04  ssr: false,05  loading: () => null,06});07 08export default ChatWidget;
ssr: false → the component is skipped on the server entirely.

02 · Render stable initial values, update on mount

For timestamps and relative dates, render the ISO value on the server and compute the “3 seconds ago” label in useEffect.

app/components/TimeAgo.tsx
tsx
01"use client";02 03import { useEffect, useState } from "react";04import { formatRelative } from "date-fns";05 06export function TimeAgo({ iso }: { iso: string }) {07  const [label, setLabel] = useState(iso);08 09  useEffect(() => {10    setLabel(formatRelative(new Date(iso), new Date()));11  }, [iso]);12 13  return <time dateTime={iso}>{label}</time>;14}
Server renders ISO, client swaps to relative after mount.

03 · Load third-party scripts with next/script

Cookie banners, chat widgets, analytics — load them via next/script with strategy="lazyOnload" so they inject after hydration completes.

app/layout.tsx
tsx
01import Script from "next/script";02 03export default function RootLayout({04  children,05}: {06  children: React.ReactNode;07}) {08  return (09    <html>10      <body>11        {children}12        <Script13          src="https://widget.example.com/loader.js"14          strategy="lazyOnload"15        />16      </body>17    </html>18  );19}
lazyOnload waits until after hydration — no mismatch.

When suppressHydrationWarning is the wrong fix

Nearly every page ranking for this error presents suppressHydrationWarningas the fix. React’s own reference presents it as the opposite: a boolean for the rare cases, like timestamps, where an exact server/client match is very hard or impossible to guarantee, and one that — in React’s words — “only works one level deep, and is intended to be used as an escape hatch. Don’t overuse it.” Those two clauses are the whole story, and the first is the one that gets people.

One level deepmeans the attribute suppresses warnings for that element’s own attributes and content, and nothing below it. Put it on a wrapper <div>in the hope of quieting a noisy subtree and you have changed nothing except your own visibility: the child that actually mismatches still mismatches, React still bails out of hydrating that tree in production, and the console line that would have told you where is now gone. That is the specific way this “fix” makes a hydration bug harder to find than it was before.

The distinction that decides it is whether the mismatch is intended. A rendered Date.now()or a locale- formatted number is genuinely different on the two sides by design, and no refactor removes that — suppression is correct and belongs on the exact element holding the value. A component that reads localStorage, branches on window, or generates an id at render time is producing an unintended difference, and suppressing it hides a real divergence that will keep costing you interactivity in production.

  1. Is the difference deliberate? If you cannot name the value that is legitimately allowed to differ, it is a bug, not a timestamp.
  2. Is the attribute on the element that holds it? On a parent it does nothing for the child. Move it down to the exact node.
  3. Does the tree still hydrate? Suppression silences the warning; it does not restore hydration for a subtree React has already given up on. Confirm interactivity, not console silence.
  4. Would useEffect or ssr: false remove it entirely? If yes, take that instead. An escape hatch used where a fix exists is technical debt with a comment attached.
Tried the fix and still broken?

Send your app URL. A senior engineer records a 10-minute teardown.

Free, and fully async — no call to book. A senior engineer walks your app on video: what’s broken, what’s risky, what to fix first. In your inbox within 24 hours. Want the code read line by line instead? Send the repo for the $49 audit.

Why do AI-built apps hit Next.js hydration error production?

AI-generated React code does not distinguish between server and client contexts. The model writes a component that reads localStorage for a theme preference, and the same component later becomes a server component because you wrapped the page in a layout that made it one. localStorage does not exist on the server. Next.js renders the server version as empty or default, ships the HTML, and the client then tries to hydrate with a different value — hydration error. The model has no way of knowing the component later changed context.

The second common source is timestamp rendering. A product card that shows “posted 3 seconds ago” using Date.now() produces 3 seconds on the server and 4 seconds by the time the client mounts. React compares the text nodes, finds them different, throws. The fix is to render a stable initial value (the ISO timestamp) and compute the relative time in useEffect. The server still renders something sensible for SEO; the client replaces it on mount.

The third pattern is third-party script injection. Chatbots, cookie banners, and A/B testing tools mount DOM before React hydrates. The DOM now contains nodes the React tree does not know about. React panics and re-renders. The fix is either to load the script with next/script and a strategy="lazyOnload", or to mount the component inside useEffect so React never sees the injection at hydration time. Nearly every hydration error traces to one of these three shapes.

Which AI builders ship Next.js hydration error production?

How often each AI builder ships this error and the pattern that produces it.

AI builder × Next.js hydration error production
BuilderFrequencyPattern
LovableHighlocalStorage read during render; component later promoted to server component
Bolt.newHighDate.now() in a relative-time helper that renders on both sides
v0MediumConditional render on window width; server renders one layout, client renders another
CursorMediumThird-party script injected via inline <script> before React mounts
Claude CodeLowOccasionally uses Math.random() for an id; rare but happens

How do I stop Next.js hydration error production recurring?

Still stuck with Next.js hydration error production?

Emergency triage · $299 · 48h turnaround
We restore service and write the root-cause report.

When hydration fires on five or more routes or only reproduces for some users, a fixed-price engagement ships this week:

  • →Hydration warning on multiple routes you cannot track down
  • →Works locally, fires only in production — intermittent
  • →Third-party scripts (cookie banner, chatbot) you cannot migrate to next/script
  • →You need a Playwright repro to catch regressions
start the triage →

Next.js hydration error production questions

What does the Next.js hydration error in production actually mean?+
Next.js renders the page on the server into HTML, then the browser downloads the JavaScript and re-renders the same components. Hydration is the process of attaching React event handlers to that server-rendered HTML. If the client render produces different output than the server render, React cannot attach handlers cleanly and throws the 'Hydration failed because the initial UI does not match' error. The UI may look correct, but interactivity is broken on the affected subtree and the console is red. Cause is almost always Date.now, localStorage, window, or a conditional render in a server component.
Which APIs cause the Next.js hydration error in production?+
Any API that returns a different value on the server than in the browser. Date.now() and new Date() because server and client clocks differ. Math.random() for the same reason. window, document, localStorage, and sessionStorage because they do not exist on the server. User-locale formatting because the server does not know the browser's locale. Third-party scripts — chatbots, cookie banners, A/B testing tools — that inject DOM before React hydrates. All of these need guarding with useEffect, a dynamic import with ssr: false, or next/script with strategy='lazyOnload'.
Why does the Next.js hydration error only happen in production?+
In development, Next.js shows a verbose hydration warning and renders both outputs so the page still works. In production, React bails out of hydration and re-renders the entire tree on the client, which looks like a flash of unstyled content and breaks interactivity on some elements. The bug was always there — production is just the first place the consequences are visible to users. Run 'npm run build && npm start' locally to see the same behavior on your laptop before deploying, and hit the page on mobile Safari to catch iOS-specific timing issues.
Is suppressHydrationWarning a real fix for this error?+
It is an escape hatch, not a fix. React's own reference describes it as intended for the rare cases, like timestamps, where an exact match is very hard or impossible to guarantee, and states that it 'only works one level deep, and is intended to be used as an escape hatch. Don't overuse it.' Use it for intentional differences — a timestamp that updates every second, a randomized id on a form — but not to silence a real bug. The mismatch is still happening; you just hid the warning. The real fixes are: move state reads into useEffect, use dynamic(..., { ssr: false }) for browser-only components like chat widgets, render ISO timestamps on the server and swap to relative time after mount, and load third-party scripts through next/script with strategy='lazyOnload'.
Why did suppressHydrationWarning not silence my hydration warning?+
Because it only works one level deep, and you almost certainly put it on a parent. React applies it to that element's own attributes and content — not to its descendants. On a wrapper div it does nothing for the child that actually mismatches, so the warning keeps firing from below. It also does not restore hydration: in production React has already bailed out of the mismatched tree and re-rendered on the client, and suppressing the message does not change that. Move the attribute onto the exact element holding the differing value, and if you cannot name what is legitimately allowed to differ there, fix the divergence instead of suppressing it.
How long does a hydration error production fix take, and when do I need help?+
Twenty minutes for a single component once you identify the offending API — grep for Date.now, new Date, Math.random, window, document, localStorage, sessionStorage, and navigator in the component body. One to two hours for an app-wide audit when hydration errors fire on multiple pages. The Emergency Triage at $299 covers a hydration investigation in 48 hours when the error fires intermittently, only reproduces for some users, or is coming from a third-party script (cookie banner, chatbot) you cannot migrate to next/script. The deliverable includes a Playwright regression test so it cannot ship again.
Next step

Ship the fix. Keep the fix.

Emergency Triage restores service in 48 hours. Break the Fix Loop rebuilds CI so this error cannot ship again.

About the author

Hyder Shah leads Afterbuild Labs, shipping production rescues for apps built in Lovable, Bolt.new, Cursor, Replit, v0, and Base44. our rescue methodology.

Next.js hydration error production experts

If this problem keeps coming back, you probably need ongoing expertise in the underlying stack.

Sources