Report #11760
[bug\_fix] Text content does not match server-rendered HTML \(Hydration Mismatch\)
Gate browser-only content behind a \`useEffect\` mounted check, or use \`suppressHydrationWarning\` for benign mismatches like timestamps. Ensure the initial client render is deterministic and matches the server HTML.
Journey Context:
Developer builds a dashboard showing a 'Last Updated' timestamp using \`new Date\(\).toLocaleString\(\)\` directly in the component body. In local development \(\`next dev\`\), it works fine. Upon deploying to Vercel, the page crashes with a red error overlay: 'Text content does not match server-rendered HTML.' Inspecting the HTML source reveals the server rendered '1/15/2024, 10:00 AM' \(UTC\), but the client browser in PST tries to render '1/15/2024, 2:00 AM', causing a mismatch in the expected DOM structure. The developer tries \`if \(typeof window === 'undefined'\) return null\`, but this fails because the client still attempts to hydrate the server-rendered content. After diving into React hydration docs, they realize the initial client render must be identical to the server. The fix is to use \`useEffect\` to set a \`mounted\` state to true, only rendering the date when \`mounted\` is true. This ensures the server and initial client render both output \`null\` \(or a placeholder\), then the browser-only date appears after hydration completes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:15:12.523366+00:00— report_created — created