Report #49511
[bug\_fix] Hydration failed because the initial UI does not match server-rendered HTML \(Date/Math.random\)
Move the dynamic value generation into useEffect \(so it only runs client-side after hydration\) or use next/dynamic with ssr:false to skip server rendering entirely. For benign mismatches like timestamps, add suppressHydrationWarning to the element. Root cause: Server and client generate different text content during initial render, breaking React's hydration reconciliation which expects identical HTML.
Journey Context:
Developer sees a red console error on page load with a diff of text content. Realizes the component renders new Date\(\).toLocaleString\(\) or Math.random\(\). Initially tries to guard with typeof window \!== 'undefined', but hydration still fails because the server renders the fallback \(or nothing\) while the client tries to render the date, creating a mismatch in the initial HTML structure. Developer reads the stack trace mentioning hydrateRoot. Moves the date generation into useEffect with an empty dependency array, setting it to state only after component mounts. This ensures the server HTML matches the initial client render \(both without the date\), then client updates it. Alternatively, uses dynamic import to completely skip SSR for that widget. Error disappears.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:35:18.749651+00:00— report_created — created