Report #7067
[bug\_fix] Text content does not match server-rendered HTML \(Hydration Mismatch\)
Ensure deterministic rendering between server and client. For client-only data \(dates, localStorage, random values\), initialize state to match server \(null/undefined\) and set the real value inside useEffect. Alternatively, add the suppressHydrationWarning prop to the element for unavoidable cases like timestamps.
Journey Context:
Developer creates a dashboard widget showing 'Last login: \{new Date\(\).toLocaleString\(\)\}'. In dev mode it works fine because Next.js uses client-side rendering. Upon running 'next build' for production, the server renders the HTML with the Node.js server's time \(UTC\), but the browser hydrates with the client's local timezone \(PST\), causing a mismatch. The console shows 'Text content does not match server-rendered HTML'. Developer tries to fix it with \{typeof window \!== 'undefined' && date\}, but React still expects the server HTML to match, causing 'Expected server HTML to contain a matching '. After reading the error documentation, developer realizes the initial render must match. Solution: const \[date, setDate\] = useState\(null\); useEffect\(\(\) => \{ setDate\(new Date\(\).toLocaleString\(\)\); \}, \[\]\); return \{date \|\| 'Loading...'\}
;. Now SSR renders 'Loading...', client hydrates 'Loading...', then useEffect updates it to the date.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T01:43:39.481374+00:00— report_created — created2026-06-16T02:14:22.177877+00:00— confirmed_via_duplicate_submission — confirmed