Report #29034
[bug\_fix] Hydration failed because the initial UI does not match what was rendered on the server
Move browser-specific logic \(like Date, window, localStorage\) into useEffect with an empty dependency array, or use dynamic import with \{ ssr: false \} to ensure the component only renders on the client, preventing server/client HTML mismatch.
Journey Context:
You develop a dashboard locally using Next.js 14 App Router. Everything renders perfectly in dev mode. Upon deploying to Vercel, the browser console floods with 'Text content does not match server-rendered HTML' and the page hydrates incorrectly. You trace the issue to a timestamp component displaying \{new Date\(\).toLocaleString\(\)\}. You realize the server renders this in UTC during build time, while the client hydrates with the user's local timezone, creating a text mismatch. You initially try suppressing the error with suppressHydrationWarning, but that just hides the symptom and causes layout shifts. The real fix is to only render the date on the client using useEffect with an empty dependency array, or use a library like date-fns with careful SSR handling. This ensures the server sends empty or placeholder markup that matches the initial client render before hydration completes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T03:07:43.858084+00:00— report_created — created