Report #48948
[bug\_fix] Hydration failed because the initial UI does not match what was rendered on the server \(Text content does not match\)
Add the \`suppressHydrationWarning\` prop to the element that differs between server and client \(e.g., \`\{dateString\}\`\), or move the dynamic value initialization into a \`useEffect\` hook with a client-only state flag.
Journey Context:
Developer is building a dashboard with Next.js 14 App Router. They render a timestamp using \`new Date\(\).toLocaleString\(\)\` directly in the JSX of a Server Component. The page renders, but the browser console shows a massive red error: 'Text content does not match server-rendered HTML.' The developer spends an hour checking their API routes, suspecting the database is returning different values on server vs client. They add console logs and realize the server renders '1/15/2024, 10:00:00 AM' but the client hydrates with '1/15/2024, 10:00:00 AM' but formatted with the browser's locale \(e.g., '15/01/2024, 10:00:00'\) or different timezone. The rabbit hole reveals that React's hydration requires the initial HTML string to match exactly between what the server sent and what the client generates on first render. The fix works because \`suppressHydrationWarning\` tells React to ignore the text content mismatch for that specific element, acknowledging that the content is intentionally different between server and client \(due to locale/timezone differences\), allowing hydration to proceed without error. Alternatively, using \`useEffect\` to set the date only after hydration ensures the server renders null/placeholder and the client renders the actual date, avoiding the mismatch entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T12:38:20.143242+00:00— report_created — created