Report #95241
[bug\_fix] Text content does not match server-rendered HTML \(caused by Date/timezone differences between server and client rendering different timestamps\)
Render the date/time only on the client using useEffect to initialize the state, or use a formatted date string that is identical on both server and client \(e.g., using toISOString with consistent timezone\), or add suppressHydrationWarning
Journey Context:
Developer displays current time using \`new Date\(\).toLocaleString\(\)\` in a component. In development with HMR it works fine, but on production build or hard refresh, React throws a hydration mismatch error. Inspecting the HTML shows the server rendered '1/15/2024, 3:00:00 PM' while the client expects '1/15/2024, 10:00:00 AM' due to timezone differences \(server in UTC, client in PST\). Developer initially tries to force UTC on both sides but formatting differences persist. Eventually implements a 'mounted' state initialized in useEffect: \`const \[date, setDate\] = useState\(null\); useEffect\(\(\) => setDate\(new Date\(\)\), \[\]\);\` and renders \`\{date ? date.toLocaleString\(\) : \}\`. This ensures the date is never rendered on the server, avoiding the mismatch. The fix works because it guarantees the markup is identical during hydration; the client only renders the time-sensitive content after hydration is complete.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T18:26:27.365966+00:00— report_created — created