Report #92160
[bug\_fix] Text content does not match server-rendered HTML \(Hydration mismatch caused by Date.now\(\), Math.random\(\), or browser extensions\)
Move dynamic data initialization into useEffect so it only runs on the client, use suppressHydrationWarning for benign mismatches like timestamps, or use useSyncExternalStore with a server snapshot.
Journey Context:
Developer adds a timestamp showing 'Last updated: \{new Date\(\).toLocaleString\(\)\}' to a footer component. In development with Fast Refresh, everything looks fine, but on production build \(next build && next start\), the console explodes with React hydration errors. Checking the HTML source reveals the server rendered '2024-01-15T10:00:00Z' while the client browser in a different timezone renders '2024-01-15T05:00:00'. Developer tries wrapping it in typeof window \!== 'undefined' but this fails because the initial server HTML still differs from the first client render. After digging into the React docs on hydration, they realize the server and client HTML must match for the first paint. They refactor to const \[date, setDate\] = useState\(null\) and set it inside useEffect\(\(\) => setDate\(new Date\(\)\), \[\]\), rendering null or a placeholder on the server. This eliminates the mismatch because both server and client initially render the placeholder, then client updates.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T13:16:49.205649+00:00— report_created — created