Report #14683
[bug\_fix] Hydration failed because the initial UI does not match what was rendered on the server \(Text content does not match server-rendered HTML\)
Move dynamic / browser-dependent values \(like \`new Date\(\)\`, \`window\`, \`localStorage\`, or \`Math.random\(\)\`\) inside a \`useEffect\` hook so they only run on the client, or use \`suppressHydrationWarning\` for text nodes where the difference is expected and harmless.
Journey Context:
Developer uses \`const now = new Date\(\).toLocaleString\(\)\` directly in a component's JSX. In development with Hot Module Replacement, the server and client often match by chance, but in the production build the server renders UTC/GMT while the browser renders the user's local timezone. The console throws 'Text content does not match'. Developer tries to suppress the warning with \`dangerouslySetInnerHTML\` or checks \`typeof window\`, but \`window\` check still runs during SSR in some Node environments. After digging through React docs, they realize the only safe approach is to gate the render: \`const \[mounted, setMounted\] = useState\(false\); useEffect\(\(\) => setMounted\(true\), \[\]\);\` and only render the date when \`mounted\` is true. This ensures the server and initial client render match \(both omit the date\), and the date appears after hydration.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T22:13:34.296477+00:00— report_created — created