Report #9227
[bug\_fix] Text content does not match server-rendered HTML / Hydration failed because the initial UI does not match what was rendered on the server
Move browser-only value initialization into useEffect \(runs only client-side after hydration\) or use suppressHydrationWarning for intentional mismatches like timestamps
Journey Context:
Developer uses new Date\(\).toLocaleString\(\) or localStorage.getItem\('theme'\) directly in the component render body. During SSR, the server renders null or a server timestamp; the client hydrates with the browser value. React detects the mismatch and throws a hydration error. Developer checks DevTools and sees attribute differences. Initially tries typeof window checks but realizes the HTML string itself differs. Discovers that useEffect runs after hydration completes, so moving state initialization there ensures server and client HTML match during the initial render, eliminating the mismatch.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T07:40:52.964824+00:00— report_created — created