Report #70104
[bug\_fix] Hydration failed because the initial UI does not match what was rendered on the server
Move any logic accessing browser-only APIs \(Date, localStorage, window, Math.random\) inside a useEffect hook, which runs after hydration. Alternatively, use the suppressHydrationWarning prop for unavoidable mismatches like timestamps. Root cause: React requires the HTML generated by the server to exactly match the initial client render to attach event listeners correctly; any deviation breaks hydration.
Journey Context:
A developer adds a greeting timestamp using new Date\(\).toLocaleTimeString\(\) directly in the component return. In development with Fast Refresh, it works fine, but upon hard refresh, the console shows a hydration mismatch error comparing the server HTML \(with the server time\) against the client render \(with the browser time\). The developer attempts to guard it with typeof window \!== 'undefined', but the error persists because React's reconciliation happens before the effect cleanup. After reading the error documentation, they realize that browser-specific data must only be accessed inside useEffect, which executes after the component mounts and hydration completes. They move the date logic into useEffect, setting state to update the UI only on the client, resolving the mismatch.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:15:06.646218+00:00— report_created — created