Interview question
Fix a time-based hydration mismatch
Moves non-deterministic browser-only rendering behind a stable server snapshot and post-hydration update.
TL;DR
Moves non-deterministic browser-only rendering behind a stable server snapshot and post-hydration update.
Hydration determinism, time zones, server snapshots, client enhancement, and avoiding suppression.
Practice the problem like a real interview: restate, reason, implement, and test.
The server sends an ISO timestamp. Render a deterministic UTC value initially, then enhance to local time after hydration without changing semantic meaning.
Next in Frontend Labs: Behavior Test
Server and first client render match; after mount the display changes to the user's locale without a hydration warning.
suppressHydrationWarning as the fix.The first render uses a stable formatter shared by server and client. An effect marks hydration complete before browser-local formatting.
export function EventTime({ iso }: { iso: string }) {
const [hydrated, setHydrated] = useState(false);
useEffect(() => setHydrated(true), []);
const timestamp = Date.parse(iso);
if (!Number.isFinite(timestamp)) return <span>Time unavailable</span>;
const instant = new Date(timestamp);
const label = hydrated
? new Intl.DateTimeFormat(undefined, { dateStyle: "medium", timeStyle: "short" }).format(instant)
: `${instant.toISOString().slice(0, 16).replace("T", " ")} UTC`;
return <time dateTime={iso}>{label}</time>;
}
The deterministic initial label avoids mismatch; local enhancement causes one intentional client update.
new Date() independently on each side.Spot a weak answer, missing edge case, or clearer explanation? Send it in.