Skip to content

Commit

Permalink
fix: use proper datetime to fix server-side/client-siode mismatch (#5479
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ovflowd authored Jul 7, 2023
1 parent a360981 commit 201d2e3
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 29 deletions.
10 changes: 8 additions & 2 deletions layouts/BlogIndexLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import BaseLayout from './BaseLayout';
import Pagination from '../components/Pagination';
import LocalizedLink from '../components/LocalizedLink';
import { useBlogData } from '../hooks/useBlogData';
import { getTimeComponent } from '../util/getTimeComponent';
import type { FC, PropsWithChildren } from 'react';
import type { BlogPost } from '../types';

Expand Down Expand Up @@ -40,7 +39,14 @@ const BlogIndexLayout: FC<PropsWithChildren> = ({ children }) => {
<ul className="blog-index">
{posts.map((post: BlogPost) => (
<li key={post.slug}>
{getTimeComponent(post.date.toString(), '%d %b')}
<time dateTime={post.date}>
{new Date(post.date).toLocaleString('en-GB', {
timeZone: 'UTC',
month: 'short',
day: '2-digit',
})}
</time>

<LocalizedLink href={post.slug}>{post.title}</LocalizedLink>
</li>
))}
Expand Down
11 changes: 9 additions & 2 deletions layouts/BlogPostLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { FormattedMessage } from 'react-intl';
import BaseLayout from './BaseLayout';
import { useLayoutContext } from '../hooks/useLayoutContext';
import { getTimeComponent } from '../util/getTimeComponent';
import type { FC, PropsWithChildren } from 'react';
import type { LegacyBlogFrontMatter } from '../types';

Expand All @@ -21,7 +20,15 @@ const BlogPostLayout: FC<PropsWithChildren> = ({ children }) => {
id="layouts.blogPost.author.byLine"
values={{ author: author || null }}
/>
{getTimeComponent(date)}

<time dateTime={date}>
{new Date(date).toLocaleString('en-GB', {
timeZone: 'UTC',
month: 'short',
day: '2-digit',
year: 'numeric',
})}
</time>
</span>
</div>

Expand Down
10 changes: 8 additions & 2 deletions layouts/CategoryIndexLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import BaseLayout from './BaseLayout';
import LocalizedLink from '../components/LocalizedLink';
import { useLayoutContext } from '../hooks/useLayoutContext';
import { useBlogData } from '../hooks/useBlogData';
import { getTimeComponent } from '../util/getTimeComponent';
import type { FC, PropsWithChildren } from 'react';
import type { BlogPost } from '../types';

Expand All @@ -24,7 +23,14 @@ const CategoryIndexLayout: FC<PropsWithChildren> = ({ children }) => {
<ul className="blog-index">
{posts.map((post: BlogPost) => (
<li key={post.slug}>
{getTimeComponent(post.date.toString(), '%d %b %y')}
<time dateTime={post.date}>
{new Date(post.date).toLocaleString('en-GB', {
timeZone: 'UTC',
month: 'short',
day: '2-digit',
})}
</time>

<LocalizedLink href={post.slug}>{post.title}</LocalizedLink>
</li>
))}
Expand Down
2 changes: 1 addition & 1 deletion next-data/generateBlogPostsData.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const getFrontMatter = (filename, source) => {
} = graymatter(source).data;

// we add the year to the pagination set
blogMetadata.pagination.add(new Date(date).getFullYear());
blogMetadata.pagination.add(new Date(date).getUTCFullYear());

// we add the category to the categories set
blogMetadata.categories.add(category);
Expand Down
9 changes: 0 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"remark-gfm": "^3.0.1",
"semver": "^7.5.3",
"sharp": "^0.32.1",
"strftime": "^0.10.2",
"turbo": "^1.10.7",
"typescript": "^5.1.6"
},
Expand Down
2 changes: 1 addition & 1 deletion theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ export default memo(
// that comes from `getStaticProps`. This means that the `props` should never change.
// At least the `props.content` should never. We should not calculate based on `children`
// As this component should never have a dynamic children
(prev, next) => JSON.stringify(prev.content) === JSON.stringify(next.content)
(prev, next) => JSON.stringify(prev) === JSON.stringify(next)
);
4 changes: 0 additions & 4 deletions util/formatTime.ts

This file was deleted.

7 changes: 0 additions & 7 deletions util/getTimeComponent.tsx

This file was deleted.

2 comments on commit 201d2e3

@vercel
Copy link

@vercel vercel bot commented on 201d2e3 Jul 7, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 201d2e3 Jul 7, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

nodejs-org-stories – ./

nodejs-org-storybook.vercel.app
nodejs-org-stories-openjs.vercel.app
nodejs-org-stories-git-main-openjs.vercel.app

Please sign in to comment.