Rendering strategies · mid
Hydration errors in Next.js
A hydration error means the HTML the server sent differs from the client's first render; in Next.js the usual causes are dates and time zones, random values, browser-only reads, invalid HTML nesting and browser extensions, and the fix is to make the first render deterministic.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Server and client often run in different time zones (UTC server, IST user):
toLocaleString()withouttimeZoneproduces different text. - Other causes:
Math.random()/Date.now()in render,typeof windowbranches,localStorage/matchMediareads in render, invalid nesting (<div>in<p>,<a>in<a>), extensions changing the DOM. - Fixes: format with an explicit
timeZoneand locale (or send pre-formatted strings),useIdfor ids, read browser-only data after hydration (effect) or with React 19.3use(browser())inside Suspense. dynamic(() => import("./Map"), { ssr: false })skips server rendering for a component; it must be called from a Client Component.suppressHydrationWarningonly for one intentional element-level difference (like a timestamp); it is not a global fix.- React 19 shows a single error with a diff and ignores unexpected tags extensions add to
<head>/<body>. - Cache Components separately flags
Math.random(),Date.now()andcrypto.randomUUID()during prerender: useawait connection()+ Suspense for per-request values, or"use cache"to share one value.
The red pen
Common traps: mistake → fix
Mistake: "Wrap everything in
ssr: false"Fix: you lose SEO and fast first paint.
Mistake: "Ignore the warning in production"
Fix: React discards the server HTML for that part and re-renders, costing performance and sometimes losing state.
Mistake: "
useEffect+mountedflag is the only fix"Fix: often deterministic formatting is the real fix.
Easy to hard
Questions interviewers ask, easy to hard
- We get a hydration mismatch on a component that formats dates. First hypothesis?
- List other common causes and fixes.
- When is
suppressHydrationWarningacceptable? ssr: falsevsuse(browser())vs a mounted flag: compare.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.