Report #76248
[bug\_fix] Hydration failed because the initial UI does not match what was rendered on the server \(Text content does not match\)
Wrap client-only values \(Date.now\(\), Math.random\(\), localStorage\) in useEffect with an isClient state gate, or add the \`suppressHydrationWarning\` prop for intentional mismatches. This eliminates the diff between the server HTML and the client React tree by ensuring the server renders a placeholder that matches exactly, with the client updating after hydration.
Journey Context:
Developer creates a timestamp component showing 'Last updated: \{Date.now\(\)\}' or uses Math.random\(\) to generate temporary IDs. In Next.js App Router, the server renders the page with one timestamp, but when React hydrates on the client, the timestamp is different, triggering the hydration mismatch error. Developer attempts to fix by checking typeof window \!== 'undefined', but this still runs during the initial client render creating a mismatch. They try dangerouslySetInnerHTML workarounds. The correct fix is using useEffect to set state after mount, or suppressHydrationWarning for unavoidable mismatches like date locales. This works because it guarantees the initial HTML from the server matches the first client render, allowing React to hydrate successfully before applying client-only updates.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T10:34:45.122556+00:00— report_created — created