Report #24860
[bug\_fix] Hydration failed because the initial UI does not match what was rendered on the server
Move browser-only logic into useEffect or use dynamic import with ssr: false. The root cause is that window/document objects don't exist during server-side rendering, causing a mismatch between the HTML generated on the server and the first client render.
Journey Context:
You add a simple \`const width = window.innerWidth\` at the top of your component to make it responsive. In development, everything works fine on the initial load, but on hard refresh or production build, you get a red console error about hydration mismatch. You check the network tab and see the server HTML has a different value than what the client renders. You try wrapping it in a check \`typeof window \!== 'undefined'\` but the error persists because React still expects the initial render to match the server HTML. After diving into the React docs, you realize that any code accessing browser APIs must run after hydration, inside useEffect, which only runs on the client.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:08:20.847871+00:00— report_created — created