Report #57744
[bug\_fix] Hydration failed because the initial UI does not match what was rendered on the server when using Date.now\(\), new Date\(\), or Math.random\(\) directly in JSX.
Move the dynamic value generation into a useEffect hook with an empty dependency array so it only executes on the client after hydration, or use suppressHydrationWarning prop if the mismatch is intentional and harmless. Root cause: During SSR, the server renders one value \(e.g., timestamp at request time\), but the client hydrates with a different value \(current timestamp\), causing React's checksum comparison to fail.
Journey Context:
You add a 'Last updated: \{new Date\(\).toLocaleString\(\)\}' timestamp to your footer. In development, you see a console error: 'Text content does not match server-rendered HTML'. Inspecting the HTML, you see the server sent '10:00:00' but the client expected '10:00:05'. You try wrapping the component in 'use client' but the error persists because the component still renders different values on server versus client execution. Searching React documentation on hydration mismatches, you find the pattern of initializing state to null and setting the date in useEffect. You implement: 'const \[date, setDate\] = useState\(null\); useEffect\(\(\) => setDate\(new Date\(\)\), \[\]\);' and conditionally render \{date ? date.toLocaleString\(\) : 'Loading...'\}. The error disappears because the server and client initial HTML both show 'Loading...', then the client updates it after hydration.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:24:49.897405+00:00— report_created — created