nextjs
render_error
ai_generated
partial
Error: Hydration failed because the initial UI does not match what was rendered on the server
ID: nextjs/hydration-failed
60%Fix Rate
82%Confidence
285Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 14 | active | — | — | — |
Root Cause
Server-rendered HTML doesn't match client-side render. Common with dynamic content, dates, or browser APIs.
genericWorkarounds
-
82% success Move browser-only code into useEffect
const [mounted, setMounted] = useState(false); useEffect(() => setMounted(true), []);
Sources: https://nextjs.org/docs/messages/react-hydration-error
-
78% success Use dynamic import with ssr: false for client-only components
const Comp = dynamic(() => import('./Comp'), { ssr: false })Sources: https://nextjs.org/docs/app/building-your-application/optimizing/lazy-loading
Dead Ends
Common approaches that don't work:
-
Suppress hydration warnings with suppressHydrationWarning
65% fail
Masks real bugs, content will flash/shift for users
-
Make everything client-side with 'use client'
78% fail
Loses all SSR/SSG benefits, defeats the purpose of Next.js
Error Chain
Preceded by:
Frequently confused with: