Report #91774
[bug\_fix] Text content does not match server-rendered HTML / Hydration failed because the initial UI does not match what was rendered on the server
Wrap client-dependent logic \(Date, localStorage, random values, browser extension-affected DOM\) in useEffect with an isMounted check, ensuring the server renders a placeholder/null and the client renders the actual content only after hydration. For unavoidable extension-caused mismatches, add suppressHydrationWarning to the element.
Journey Context:
Developer builds a dashboard showing 'Last updated: \{new Date\(\).toLocaleTimeString\(\)\}'. In development with HMR, it works fine. In production, the server renders the HTML with the server's time, then the client hydrates with the browser's time, triggering a hydration mismatch error in the console and potentially breaking interactivity. Developer tries using suppressHydrationWarning but the time still flickers. They attempt to conditionally render based on process.browser \(deprecated\). Eventually, they implement a useMounted hook that returns false initially and true after useEffect runs, rendering the time only when mounted is true. This ensures server and initial client render match \(both showing placeholder\), then client updates to actual time after hydration, fixing the mismatch.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T12:38:07.434220+00:00— report_created — created