Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automatically provide localised Date for SSR in RelativeTime #4305

Merged

Conversation

keithamus
Copy link
Member

@keithamus keithamus commented Feb 26, 2024

Closes #4361

Changelog

New

<RelativeTime/> now renders dates in SSR.

Changed

Removed

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

Merge checklist

Copy link

changeset-bot bot commented Feb 26, 2024

🦋 Changeset detected

Latest commit: ff29e49

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

@github-actions github-actions bot temporarily deployed to storybook-preview-4305 February 26, 2024 12:47 Inactive
@keithamus keithamus force-pushed the automatically-provide-localised-date-for-ssr-in-relativetime branch 2 times, most recently from db5e8a1 to 79e23a9 Compare March 6, 2024 12:02
@keithamus keithamus force-pushed the automatically-provide-localised-date-for-ssr-in-relativetime branch from 79e23a9 to 5eaee82 Compare March 6, 2024 12:03
@keithamus keithamus marked this pull request as ready for review March 6, 2024 12:06
@keithamus keithamus requested review from a team and broccolinisoup March 6, 2024 12:06
Copy link
Contributor

github-actions bot commented Mar 6, 2024

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 87.54 KB (+0.14% 🔺)
packages/react/dist/browser.umd.js 87.81 KB (+0.07% 🔺)

packages/react/src/RelativeTime/RelativeTime.tsx Outdated Show resolved Hide resolved
const localeOptions: Intl.DateTimeFormatOptions = {month: 'short', day: 'numeric', year: 'numeric'}
function RelativeTime({date, ...props}: RelativeTimeProps) {
return (
<RelativeTimeComponent {...props} date={date}>
Copy link
Member

Choose a reason for hiding this comment

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

When I pass datetime instead of date, like <RelativeTime datetime="2024-03-10T16:30:00-08:00" /> in a sample app, it doesn't render any date in SSR. Seems like the props return undefined. Is there anything I am missing here? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

I've fixed this and added tests to confirm.

Copy link
Collaborator

@camertron camertron left a comment

Choose a reason for hiding this comment

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

Is it possible to write a test that confirms the date is localized correctly in non English-speaking locales?

@keithamus
Copy link
Member Author

Is it possible to write a test that confirms the date is localized correctly in non English-speaking locales?

It won't be as the aim is to ensure it is localised to a fixed locale, so as not to impact caching.

@keithamus keithamus added this pull request to the merge queue Mar 19, 2024
Merged via the queue into main with commit 37c4770 Mar 19, 2024
30 checks passed
@keithamus keithamus deleted the automatically-provide-localised-date-for-ssr-in-relativetime branch March 19, 2024 18:42
@primer primer bot mentioned this pull request Mar 19, 2024
lukasoppermann pushed a commit that referenced this pull request Apr 16, 2024
* automatically provide localised Date for SSR in RelativeTime

* changeset

* fix and add tests

* format

* fix types
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.

RelativeTime should render some kind of date in SSR
3 participants