Report #83991
[bug\_fix] Hydration failed because the initial UI does not match what was rendered on the server. Text content does not match server-rendered HTML.
Move browser-only logic \(Math.random\(\), Date.now\(\), localStorage, window\) into useEffect or use a dynamic import with ssr: false. Ensure server and client render identical HTML for the initial paint.
Journey Context:
Developer builds a landing page with a random background image selected via Math.random\(\) directly in the component body. In development \(client-only rendering\), it works perfectly. After deploying to Vercel, the page crashes with a red hydration error overlay. Developer inspects the console and sees that the server rendered image-1.jpg but the client picked image-3.jpg. Initially tries suppressing the error with suppressHydrationWarning on the div, but the underlying mismatch still causes React to tear down and remount the entire tree, causing visible flicker and loss of form state. After searching the exact error message, developer learns that during SSR, the server executes the component once, and the client executes it again for hydration—they must produce identical HTML. The fix involves moving the random selection into useEffect \(which only runs on the client\) with a loading state placeholder, or using next/dynamic with ssr: false to exclude the component from SSR entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T23:33:57.259508+00:00— report_created — created