Report #25472
[bug\_fix] Hydration failed because the initial UI does not match what was rendered on the server \(Text content does not match\)
Move client-only data sources \(Date, Math.random, localStorage\) into useEffect so the initial render matches SSR HTML, or use the \`suppressHydrationWarning\` prop for benign mismatches like timestamps.
Journey Context:
Developer sees a red error overlay in dev mode: 'Text content does not match: Server: "0" Client: "5"'. They inspect the component and see \`const id = Math.random\(\)\` or \`const date = new Date\(\)\` directly in the component body. They try guarding with \`typeof window \!== 'undefined' && \` but the error persists because React hydrates the existing server HTML; it doesn't re-render from scratch. The 'typeof window' check actually makes the mismatch worse by rendering nothing on the server and something on the client. After reading the error page, they understand that during the initial hydration pass, the React tree must match the server snapshot exactly. They move the random/date logic into a useEffect \(which runs after hydration\), setting initial state to a stable value like \`null\` or \`0\`. For timestamps that differ by seconds, they may add \`suppressHydrationWarning\` to the element to acknowledge the intentional mismatch.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T21:09:39.577589+00:00— report_created — created