Report #86845
[bug\_fix] Hydration failed because the initial UI does not match server-rendered HTML caused by browser-only APIs like Date or Math.random used during render
Move browser-specific logic into a useEffect hook that runs after hydration, or pass suppressHydrationWarning to the element as a temporary mask while ensuring the server and client render identical initial HTML
Journey Context:
You add a timestamp showing 'Last updated: \{new Date\(\).toLocaleTimeString\(\)\}' directly in your JSX. In local development with client-side navigation, it looks perfect. However, on production builds or hard refreshes, the console erupts with 'Text content does not match server-rendered HTML.' Inspecting the source, you see the server rendered '10:00 AM' \(UTC\) while the client renders '2:00 PM' \(local time\). You consider using suppressHydrationWarning, but realize that just silences the symptom while React may still tear down and rebuild the DOM, causing input focus loss. The debugging rabbit-hole leads you to understand that during SSR, the server has no access to the client's timezone or current time. By moving the date formatting into a useEffect that only runs after mount—or by using a library like date-fns with proper SSR handling—you ensure the initial HTML matches exactly between server and client, then the client updates the display post-hydration without mismatching.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:21:27.422929+00:00— report_created — created