Skip to content

Fix RelativeTime hydration across time zones - #8330

Merged
liuliu-dev merged 3 commits into
mainfrom
fix/relative-time-hydration
Aug 31, 2026
Merged

Fix RelativeTime hydration across time zones#8330
liuliu-dev merged 3 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: f80c0da

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
@mattcosta7
mattcosta7 disabled auto-merge August 24, 2026 22:31
@mattcosta7
mattcosta7 enabled auto-merge August 25, 2026 21:32
@mattcosta7
mattcosta7 disabled auto-merge August 27, 2026 02:19
@mattcosta7 mattcosta7 added the Canary Release Apply this label when you want CI to create a canary release of the current PR label Aug 27, 2026
@liuliu-dev liuliu-dev added the integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh label Aug 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Action required

👋 Hi, there are new commits since the last successful integration test. 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 temporarily deployed to storybook-preview-8330 August 31, 2026 21:04 Inactive
@github-actions github-actions Bot removed the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Aug 31, 2026
@primer-integration

Copy link
Copy Markdown

Integration test results from github/github-ui PR:

Passed  CI   Passed
Passed  VRT   Passed
Passed  Projects   Passed

All checks passed!

@liuliu-dev
liuliu-dev added this pull request to the merge queue Aug 31, 2026
Merged via the queue into main with commit f7329dc Aug 31, 2026
54 checks passed
@liuliu-dev
liuliu-dev deleted the fix/relative-time-hydration branch August 31, 2026 21:50
@primer primer Bot mentioned this pull request Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Canary Release Apply this label when you want CI to create a canary release of the current PR integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants