DEV Community

Applied Efficiency
Applied Efficiency

Posted on

Hydration failed? Your server and browser rendered two different pages

If you vibe-code with Next.js, you'll meet this one eventually:

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

What it means: the page is rendered twice — once on the server, once in your browser. The two copies have to match exactly. When they don't, React throws the page away and starts over. Your app still works, but you get a flash, a console full of warnings, and sometimes a broken first paint.

Three usual suspects:

  1. Dates and random values in the render. new Date() or Math.random() gives a different answer on the server than in the browser. Every time.
  2. Browser-only APIs on first render. window or localStorage don't exist on the server. Reading them during render guarantees a mismatch.
  3. Invalid HTML nesting — like a <div> inside a <p>. Browsers "fix" it; the server doesn't.

The fix:

  • Move anything date-, random-, or browser-based into a useEffect that runs after mount.
  • Check the nesting the error names — hydration errors point at the exact component.
  • When in doubt, paste the full warning into your AI. It names the component; start there.

This is pattern #5 in the Debug Clinic at Last20 Academy — the five errors vibe coders hit most, each with the cause and a paste-ready fix: https://last20.appliedefficiencyai.com

Top comments (0)