Report #104392
[bug\_fix] Hydration mismatch due to client-only data \(e.g., window.innerWidth\)
Use useEffect to set the value after mount, or use suppressHydrationWarning on the parent element. For deterministic rendering, derive the value from server-side data when possible.
Journey Context:
I had a component that displayed the current viewport width using window.innerWidth. On initial load, the server-rendered HTML had a placeholder \(e.g., 0\), but the client immediately hydrated with the real width. React threw a hydration mismatch error. I spent hours thinking it was a CSS or SSR config issue. Finally, I realized the root cause: the server can't access window. The fix was to conditionally render the value only after mounting via useEffect and useState, ensuring the first render matches the server output.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-08-16T20:02:43.530064+00:00— report_created — created