Report #11571
[bug\_fix] Hydration failed because the initial UI does not match \(browser-only initial state\)
Initialize browser-dependent values inside useEffect \(after hydration\) or use the suppressHydrationWarning prop for intentional mismatches like theme classes.
Journey Context:
Developer adds a timestamp or uses \`Math.random\(\)\` in a component render: \`const \[time\] = useState\(new Date\(\).toLocaleString\(\)\)\`. Dev server works, but production build throws "Text content does not match server-rendered HTML." Developer suspects data fetching issues, checks getServerSideProps \(if migrating\), tries wrapping in \`\`. Deep investigation reveals that during SSR, \`new Date\(\)\` executes in Node.js with server timezone, while client hydrates with browser timezone, causing a text mismatch. React's hydrateRoot expects 1:1 match. The fix moves date initialization into \`useEffect\(\(\) => setTime\(new Date\(\)\), \[\]\)\` so server renders empty/placeholder initially \(matching\), then client updates post-hydration. Alternatively, \`suppressHydrationWarning\` on the element tells React to ignore the mismatch for that specific node.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T13:42:56.418027+00:00— report_created — created