Common Next.js errorsHydration failed: text didn't match
Hydration failed because the server rendered text didn't match the client means the HTML your server sent isn't what React rendered in the browser a moment later. React throws the server's version away, the page flickers, and anything that depends on it can break.
Why it happens in production
- Times and dates:
new Date().toLocaleTimeString() gives a different answer on the server and in the browser (another second, another time zone, another locale). - Random values:
Math.random() or a generated id used in the markup. - Browser-only values:
window, localStorage or screen size read during render.
How to fix it
Render the same thing on both sides, and fill in time-dependent values only after the page has loaded in the browser:
components/UpdatedTime.tsx "use client";
import { useEffect, useState } from "react";
export function UpdatedTime() {
const [time, setTime] = useState<string | null>(null);
useEffect(() => setTime(new Date().toLocaleTimeString()), []);
return <p>Updated {time ?? "just now"}</p>;
}
Pinning the locale and time zone isn't enough on its own: the seconds still differ between server and browser.
How SteadyOn handles it
SteadyOn writes a test that renders the page at two different moments and fails if the markup differs, then proves the fix makes it pass before anything ships. See When something breaks.