Skip to content

fix(docs): avoid hydration mismatch in runtime-clock live examples - #1683

Open
MilindChatrabhuji wants to merge 2 commits into
Thinkmill:mainfrom
MilindChatrabhuji:fix/datepicker-docs-hydration-1562
Open

MilindChatrabhuji wants to merge 2 commits into
Thinkmill:mainfrom
MilindChatrabhuji:fix/datepicker-docs-hydration-1562

Conversation

@MilindChatrabhuji

Copy link
Copy Markdown
Contributor

Closes #1562

Summary

  • Prevents React hydration error #418 on statically generated Keystar documentation pages containing live examples that evaluate runtime clock/timezone APIs (today(), now(), getLocalTimeZone(), new Date(), Date.now()), including DatePicker, DateField, and DateRangePicker.
  • design-system/docs/app/(site)/package/[...slug]/page.tsx statically generates doc pages at build time via generateStaticParams(), baking the build server's UTC date into SSR HTML for <RenderLiveCode>. When a client hydrates on a different date or local timezone, the initial today(getLocalTimeZone()) / now(...) text diverges from SSR HTML and triggers a hydration mismatch.

Fix

  • Update ReactLive in design-system/docs/components/mdx-components/react-live/index.tsx to detect runtime clock/timezone live snippets via useSyncExternalStore and defer mounting <RenderLiveCode> until after hydration on the client, while preserving full SSR for deterministic examples and static <Highlight> code snippets.
  • Add regression tests in design-system/docs/components/mdx-components/react-live/react-live.test.tsx covering SSR/client date drift across renderToString + hydrateRoot and deterministic SSR rendering.

Verification

  • vitest run design-system/docs/components/mdx-components/react-live/react-live.test.tsx (with design-system/docs/generated absent): 2 passed (2).
  • tsc --noEmit: exited 0.
  • eslint across the repository (pnpm check:lint .): exited 0.
  • prettier --check on both modified files: passed.

@changeset-bot

changeset-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 85a3d49

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DatePicker docs page throws React hydration error (#418) on load

1 participant