Skip to the page

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.

The notes

What you must know

  • Server and client often run in different time zones (UTC server, IST user): toLocaleString() without timeZone produces different text.
  • Other causes: Math.random()/Date.now() in render, typeof window branches, localStorage/matchMedia reads in render, invalid nesting (<div> in <p>, <a> in <a>), extensions changing the DOM.
  • Fixes: format with an explicit timeZone and locale (or send pre-formatted strings), useId for ids, read browser-only data after hydration (effect) or with React 19.3 use(browser()) inside Suspense.
  • dynamic(() => import("./Map"), { ssr: false }) skips server rendering for a component; it must be called from a Client Component.
  • suppressHydrationWarning only 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() and crypto.randomUUID() during prerender: use await 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 + mounted flag is the only fix"

    Fix: often deterministic formatting is the real fix.

Easy to hard

Questions interviewers ask, easy to hard

  1. We get a hydration mismatch on a component that formats dates. First hypothesis?
  2. List other common causes and fixes.
  3. When is suppressHydrationWarning acceptable?
  4. ssr: false vs use(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 voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview