Report #46699
[bug\_fix] Text content does not match server-rendered HTML \(Hydration mismatch\)
Move any logic that depends on browser APIs \(window, document\), timestamps \(Date.now\(\)\), or random values \(Math.random\(\)\) into a useEffect hook so it only runs on the client. Alternatively, if the mismatch is unavoidable \(e.g., timestamps\), add the suppressHydrationWarning prop to the element.
Journey Context:
You notice a console error in development or production logs stating that hydration failed because the initial UI does not match the server HTML. You inspect the DOM and see the server-rendered HTML looks correct, but React throws a warning during hydration. You initially suspect data fetching issues, then realize the component renders a timestamp using new Date\(\).toLocaleString\(\) directly in the JSX. You try wrapping it in a conditional check for typeof window \!== 'undefined', but the error persists because the server still renders a different string than what the client expects during the initial render. You finally move the date logic into useEffect with a state variable, ensuring the initial render matches the server HTML \(showing a placeholder or nothing\), and the client updates it after mount, eliminating the mismatch.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T08:51:28.930093+00:00— report_created — created