Skip to content

Commit 201d2e3

Browse files
authored
fix: use proper datetime to fix server-side/client-siode mismatch (#5479)
1 parent a360981 commit 201d2e3

File tree

9 files changed

+27
-29
lines changed

9 files changed

+27
-29
lines changed

layouts/BlogIndexLayout.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import BaseLayout from './BaseLayout';
44
import Pagination from '../components/Pagination';
55
import LocalizedLink from '../components/LocalizedLink';
66
import { useBlogData } from '../hooks/useBlogData';
7-
import { getTimeComponent } from '../util/getTimeComponent';
87
import type { FC, PropsWithChildren } from 'react';
98
import type { BlogPost } from '../types';
109

@@ -40,7 +39,14 @@ const BlogIndexLayout: FC<PropsWithChildren> = ({ children }) => {
4039
<ul className="blog-index">
4140
{posts.map((post: BlogPost) => (
4241
<li key={post.slug}>
43-
{getTimeComponent(post.date.toString(), '%d %b')}
42+
<time dateTime={post.date}>
43+
{new Date(post.date).toLocaleString('en-GB', {
44+
timeZone: 'UTC',
45+
month: 'short',
46+
day: '2-digit',
47+
})}
48+
</time>
49+
4450
<LocalizedLink href={post.slug}>{post.title}</LocalizedLink>
4551
</li>
4652
))}

layouts/BlogPostLayout.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { FormattedMessage } from 'react-intl';
22
import BaseLayout from './BaseLayout';
33
import { useLayoutContext } from '../hooks/useLayoutContext';
4-
import { getTimeComponent } from '../util/getTimeComponent';
54
import type { FC, PropsWithChildren } from 'react';
65
import type { LegacyBlogFrontMatter } from '../types';
76

@@ -21,7 +20,15 @@ const BlogPostLayout: FC<PropsWithChildren> = ({ children }) => {
2120
id="layouts.blogPost.author.byLine"
2221
values={{ author: author || null }}
2322
/>
24-
{getTimeComponent(date)}
23+
24+
<time dateTime={date}>
25+
{new Date(date).toLocaleString('en-GB', {
26+
timeZone: 'UTC',
27+
month: 'short',
28+
day: '2-digit',
29+
year: 'numeric',
30+
})}
31+
</time>
2532
</span>
2633
</div>
2734

layouts/CategoryIndexLayout.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import BaseLayout from './BaseLayout';
33
import LocalizedLink from '../components/LocalizedLink';
44
import { useLayoutContext } from '../hooks/useLayoutContext';
55
import { useBlogData } from '../hooks/useBlogData';
6-
import { getTimeComponent } from '../util/getTimeComponent';
76
import type { FC, PropsWithChildren } from 'react';
87
import type { BlogPost } from '../types';
98

@@ -24,7 +23,14 @@ const CategoryIndexLayout: FC<PropsWithChildren> = ({ children }) => {
2423
<ul className="blog-index">
2524
{posts.map((post: BlogPost) => (
2625
<li key={post.slug}>
27-
{getTimeComponent(post.date.toString(), '%d %b %y')}
26+
<time dateTime={post.date}>
27+
{new Date(post.date).toLocaleString('en-GB', {
28+
timeZone: 'UTC',
29+
month: 'short',
30+
day: '2-digit',
31+
})}
32+
</time>
33+
2834
<LocalizedLink href={post.slug}>{post.title}</LocalizedLink>
2935
</li>
3036
))}

next-data/generateBlogPostsData.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const getFrontMatter = (filename, source) => {
3535
} = graymatter(source).data;
3636

3737
// we add the year to the pagination set
38-
blogMetadata.pagination.add(new Date(date).getFullYear());
38+
blogMetadata.pagination.add(new Date(date).getUTCFullYear());
3939

4040
// we add the category to the categories set
4141
blogMetadata.categories.add(category);

package-lock.json

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"remark-gfm": "^3.0.1",
6161
"semver": "^7.5.3",
6262
"sharp": "^0.32.1",
63-
"strftime": "^0.10.2",
6463
"turbo": "^1.10.7",
6564
"typescript": "^5.1.6"
6665
},

theme.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ export default memo(
2828
// that comes from `getStaticProps`. This means that the `props` should never change.
2929
// At least the `props.content` should never. We should not calculate based on `children`
3030
// As this component should never have a dynamic children
31-
(prev, next) => JSON.stringify(prev.content) === JSON.stringify(next.content)
31+
(prev, next) => JSON.stringify(prev) === JSON.stringify(next)
3232
);

util/formatTime.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

util/getTimeComponent.tsx

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)