Report #36182
[bug\_fix] Text content does not match server-rendered HTML: Hydration failed because the initial UI does not match what was rendered on the server, often triggered by new Date\(\), Math.random\(\), or browser extensions injecting attributes into the DOM.
Move client-only data generation \(timestamps, random IDs\) inside a useEffect with an empty dependency array so it only executes after hydration, or add the suppressHydrationWarning prop to the element if the mismatch is unavoidable and harmless. The root cause is that React requires the HTML sent by the server to exactly match the initial client render for hydration to succeed.
Journey Context:
You add a timestamp showing 'Last updated: ' \+ new Date\(\).toLocaleString\(\) directly in your component's JSX. In development with hot reloading, it works fine. However, upon running next build and next start, the browser console throws a hydration error. Inspecting the HTML, you see the server sent a timestamp from build time, but the client immediately generates a new timestamp during hydration, causing a text mismatch. You initially try conditionally rendering based on typeof window \!== 'undefined', but this causes a different hydration error because the server rendered null while the client tries to render content. After reading the Next.js error documentation, you understand that the value must be generated after hydration completes. You move the date initialization into useEffect\(\(\) => setDate\(new Date\(\)\), \[\]\) and conditionally render a placeholder while date is null, which resolves the mismatch.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T15:12:22.033897+00:00— report_created — created