Report #79557
[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\)
Move browser-only logic \(accessing window, document, Date.now\(\), Math.random\(\)\) inside a useEffect that only runs after mount, or use dynamic import with \{ ssr: false \}. The root cause is that the server renders HTML with one state \(or no state\) and React expects the client first render to match exactly; any DOM mismatch breaks hydration.
Journey Context:
Developer adds a timestamp or random ID using \`new Date\(\)\` or \`Math.random\(\)\` directly in a component body. Everything works in development \(where React often suppresses strict hydration checks\), but in production build or on hard refresh, the console shows the red React hydration error. Developer tries adding suppressHydrationWarning=\{true\} to the element, but the error persists or moves elsewhere. They realize the server generated HTML with a different timestamp than the client. After checking React docs, they move the date generation into a useEffect with an empty dependency array, setting state only after mount, ensuring the server and initial client render match \(both showing a placeholder\), then the effect runs to show the real date.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T16:08:28.537690+00:00— report_created — created