Report #68963
[bug\_fix] Text content does not match server-rendered HTML / Hydration failed because the initial UI does not match
Move browser-dependent values \(Date, Math.random, window\) into a useEffect hook so the server and initial client HTML are identical, then render the dynamic value after hydration. Alternatively, use suppressHydrationWarning=\{true\} for benign mismatches like timestamps.
Journey Context:
Developer builds a dashboard with Next.js 14 App Router. Adds a welcome message showing current time: \`\{new Date\(\).toLocaleString\(\)\}\`. Works in dev, but production logs show 'Text content does not match'. Developer suspects CSS-in-JS issues, spends hours debugging styled-components, then realizes the server renders the build-time date while the client renders the browser's date. Tries \`typeof window \!== 'undefined'\` check, but this creates a mismatch because server renders null while client renders the date, still breaking hydration. Finally discovers pattern of initializing state to null and updating in useEffect, ensuring server and initial client HTML match, then client updates after mount.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T22:14:24.233996+00:00— report_created — created