Report #16332
[bug\_fix] Hydration failed because the initial UI does not match what was rendered on the server \(Text content does not match server-rendered HTML\)
Gate client-only content with a \`useEffect\` mounted check \(e.g., \`const \[mounted, setMounted\] = useState\(false\); useEffect\(\(\) => setMounted\(true\), \[\]\); if \(\!mounted\) return ;\`\). For timestamps, pass the server date as a prop or use \`suppressHydrationWarning\` for unavoidable mismatches. Root cause: React requires the initial client render to exactly match the server HTML; any divergence \(like \`new Date\(\)\` or \`localStorage\` access during render\) breaks hydration.
Journey Context:
Developer adds a timestamp to a dashboard using \`\{new Date\(\).toLocaleString\(\)\}\` directly in JSX. The page renders fine in development \(where SSR might be disabled or client-side navigation masks the issue\), but the production build throws the hydration mismatch error in the browser console. Developer attempts to guard with \`typeof window \!== 'undefined'\`, but the error persists because the condition is evaluated during the initial client render, which still produces different HTML than the server. After reading the error stack, developer realizes the server rendered a specific date string while the client rendered a different one milliseconds later. They implement a \`mounted\` state flag inside \`useEffect\` to defer the date rendering until after the initial mount, ensuring both server and client initial HTML match \(showing a skeleton or placeholder\), then the client updates the date.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:23:26.326999+00:00— report_created — created