Report #13059
[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\)
Remove non-deterministic values \(Date.now, Math.random\) from the initial render output; move them to useEffect, or use suppressHydrationWarning for unavoidable cases like browser-extension-injected markup. Ensure server and client HTML are identical during the initial hydrate.
Journey Context:
Developer implements a timestamp or random greeting displaying the current time via new Date\(\).toLocaleTimeString\(\) directly in the component body. In development with hot-reload client-side transitions, it works fine. On hard refresh or production build, the console shows a React hydration error pointing to a text node mismatch. Developer checks the Network tab and sees the server-rendered HTML contains "10:00 AM" while the client expects "2:00 PM" \(client timezone\). They suspect a React bug and try downgrading React, then realize the server renders once at build/request time with server timezone/clock, while the client hydrates with its own clock. They learn that useEffect only runs after hydration, so moving the date logic there ensures the initial HTML matches. This fix works because React requires the initial render tree to match the server snapshot exactly; any deviation, even a single text character, triggers a full client-side re-render and warning.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T17:42:18.846262+00:00— report_created — created