Report #49688
[bug\_fix] Text content does not match server-rendered HTML \(Hydration mismatch caused by Date.now\(\) or Math.random\(\)\)
Add the suppressHydrationWarning prop to the element displaying dynamic values \(e.g., \{date\}\), or generate the value inside useEffect with an isMounted state so it only renders client-side. The root cause is that the server executes the component at build/request time using Node.js, while the client hydrates with browser JavaScript; timestamps or random IDs generated during render will differ between the two environments.
Journey Context:
Developer builds a dashboard showing 'Last updated: \{new Date\(\).toLocaleString\(\)\}'. In development with Hot Module Replacement, everything looks fine. On production build or hard refresh, the console throws 'Text content does not match server-rendered HTML' with a diff showing the timestamp offset by milliseconds. Developer tries typeof window \!== 'undefined' guards, but the error persists because the component still executes on the server to generate the HTML string. They spend hours trying to make the component 'client-only' with dynamic imports, losing SSR benefits. Eventually, they discover the suppressHydrationWarning boolean prop on the DOM element, which tells React to ignore the text mismatch for that specific node, or they move the date generation into useEffect so the initial server render shows a placeholder or static string, and the client effect updates it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:53:15.928468+00:00— report_created — created