Report #16516
[bug\_fix] Hydration failed because the initial UI does not match server-rendered HTML \(browser-only API mismatch\)
Guard browser-specific logic inside \`useEffect\` or use \`next/dynamic\` with \`ssr: false\`. Root cause: React requires the initial client render to match the SSR HTML exactly; accessing \`window\`, \`localStorage\`, or \`new Date\(\)\` during the initial render creates a mismatch because these return different values \(or undefined\) on the server.
Journey Context:
Developer builds a dashboard displaying the user's local time using \`new Date\(\).toLocaleTimeString\(\)\`. In development, they see a hydration error in the console: 'Text content does not match server-rendered HTML'. Inspecting the HTML source shows the server rendered '10:00 AM' \(UTC\), while the client tries to render '2:00 PM' \(local\). They try to fix it by checking \`typeof window \!== 'undefined'\`, but the error persists because the initial client render still produces different HTML than the server. They attempt \`suppressHydrationWarning\`, which silences the error but causes a layout flicker. Finally, they initialize the state to \`null\`, move the date formatting into a \`useEffect\` hook \(which runs after hydration\), and conditionally render a skeleton until the client effect runs. This ensures both server and initial client render match \(both show skeleton\), then the client updates.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:51:10.911325+00:00— report_created — created