Report #10085
[bug\_fix] Text content does not match server-rendered HTML \(Hydration mismatch\) when using browser APIs like window or localStorage
Move browser-only logic into useEffect \(which runs only on the client\) or use next/dynamic with ssr: false. Root cause: During SSR, Node.js has no window/document; conditional rendering based on these APIs produces HTML that differs from the client hydration.
Journey Context:
Developer writes a component rendering \{typeof window \!== 'undefined' ? window.innerWidth : 0\}. On load, React throws a red hydration error. Developer tries suppressHydrationWarning but sees UI flicker. Searching StackOverflow, they learn that the server renders 0 while the client renders 800, causing a checksum mismatch. They try dynamic imports with ssr: false, which works because the component only renders on the client. Moving logic to useEffect also fixes it because effects run after hydration.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:48:09.431235+00:00— report_created — created