Skip to content

Fix RelativeTime hydration across time zones - #8330

Open
mattcosta7 wants to merge 2 commits into
mainfrom
fix/relative-time-hydration
Open

Fix RelativeTime hydration across time zones#8330
mattcosta7 wants to merge 2 commits into
mainfrom
fix/relative-time-hydration

Conversation

@mattcosta7

Copy link
Copy Markdown
Contributor

Closes #

Prevent RelativeTime fallback text from differing between server and client when they use different local time zones. The fallback now formats dates in UTC, matching deterministically across SSR and hydration.

Changelog

New

None.

Changed

  • RelativeTime uses UTC when rendering its fallback date.
  • Added regression coverage for hydration across differing server and client time zones.

Removed

None.

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

  • node node_modules/vitest/vitest.mjs run --root . --project @primer/react packages/react/src/RelativeTime/RelativeTime.test.tsx
  • Verified hydration produces no recoverable errors or console errors when server and client date formatting would otherwise resolve to different calendar days.

@changeset-bot

changeset-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4b40ea0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

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

@mattcosta7
mattcosta7 marked this pull request as ready for review August 21, 2026 13:00
Copilot AI lite review requested due to automatic review settings August 21, 2026 13:00
@mattcosta7
mattcosta7 requested a review from a team as a code owner August 21, 2026 13:00
@mattcosta7
mattcosta7 requested a review from jonrohan August 21, 2026 13:00
@mattcosta7 mattcosta7 self-assigned this Aug 21, 2026
@github-actions github-actions Bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Aug 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Action required

👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.

@github-actions
github-actions Bot requested a deployment to storybook-preview-8330 August 21, 2026 13:04 Abandoned

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates RelativeTime to render its fallback date deterministically during SSR/hydration by formatting the fallback in UTC, preventing hydration mismatches when server and client local time zones differ.

Changes:

  • Add timeZone: 'UTC' to the fallback toLocaleDateString formatting options.
  • Add a hydration regression test intended to catch mismatches when server/client time zones differ.
  • Add a patch changeset for @primer/react.
Show a summary per file
File Description
packages/react/src/RelativeTime/RelativeTime.tsx Forces fallback date formatting to UTC for consistent SSR/client output.
packages/react/src/RelativeTime/RelativeTime.test.tsx Adds a hydration regression test for differing server/client time zones.
.changeset/quiet-times-agree.md Publishes the change as a patch release entry.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment on lines +7 to +12
const localeOptions: Intl.DateTimeFormatOptions = {
month: 'short',
day: 'numeric',
year: 'numeric',
timeZone: 'UTC',
} satisfies Intl.DateTimeFormatOptions
Comment on lines +44 to +51
const toLocaleDateStringSpy = vi.spyOn(Date.prototype, 'toLocaleDateString').mockReturnValue('Mar 7, 2024')
const container = document.createElement('div')
container.innerHTML = renderToString(relativeTime)
document.body.appendChild(container)

toLocaleDateStringSpy.mockImplementation((_locales, options) =>
options?.timeZone === 'UTC' ? 'Mar 7, 2024' : 'Mar 6, 2024',
)
@mattcosta7
mattcosta7 enabled auto-merge August 21, 2026 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants