Skip to content

Commit 14d64e9

Browse files
committed
fix: suppress product card hydration mismatch
1 parent 7d82b01 commit 14d64e9

1 file changed

Lines changed: 75 additions & 61 deletions

File tree

components/Activity/ProductCard.tsx

Lines changed: 75 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,68 +10,82 @@ import styles from '../../styles/Hackathon.module.less';
1010
export type ProductCardProps = Product & Omit<CardProps, 'id' | 'title'>;
1111

1212
export const ProductCard: FC<ProductCardProps> = observer(
13-
({ className = '', id, createdAt, name, sourceLink, link = sourceLink, summary, ...props }) => (
14-
<Card className={`${styles.projectCard} ${className}`} {...props}>
15-
<Card.Body className="d-flex flex-column">
16-
<Card.Title
17-
as="a"
18-
className="text-dark fw-bold"
19-
title={name as string}
20-
target="_blank"
21-
href={link as string}
22-
>
23-
{(name || link) as string}
24-
</Card.Title>
25-
<p className="text-dark opacity-75 mb-3">{summary as string}</p>
26-
<div className="flex-fill mb-3">
27-
<FilePreview className="w-100" path={link as string} />
28-
</div>
13+
({ className = '', id, createdAt, name, sourceLink, link = sourceLink, summary, ...props }) => {
14+
const createdAtValue = Number(createdAt);
15+
const createdAtISO = Number.isFinite(createdAtValue)
16+
? new Date(createdAtValue).toJSON()
17+
: undefined;
18+
const createdAtText = Number.isFinite(createdAtValue) ? formatDate(createdAtValue) : '';
2919

30-
{sourceLink && (
31-
<div className="d-flex flex-wrap gap-2 mb-3">
32-
<Button
33-
variant="dark"
34-
size="sm"
35-
href={sourceLink as string}
36-
target="_blank"
37-
rel="noreferrer"
38-
>
39-
GitHub
40-
</Button>
41-
<Button
42-
variant="primary"
43-
size="sm"
44-
href={`https://github.dev/${(sourceLink as string).replace('https://github.com/', '')}`}
45-
target="_blank"
46-
rel="noreferrer"
47-
>
48-
GitHub.dev
49-
</Button>
50-
<Button
51-
variant="dark"
52-
size="sm"
53-
href={`https://codespaces.new/${(sourceLink as string).replace('https://github.com/', '')}`}
54-
target="_blank"
55-
rel="noreferrer"
56-
>
57-
Codespaces
58-
</Button>
59-
<Button
60-
variant="warning"
61-
size="sm"
62-
href={`https://gitpod.io/#${sourceLink as string}`}
63-
target="_blank"
64-
rel="noreferrer"
65-
>
66-
GitPod
67-
</Button>
20+
return (
21+
<Card className={`${styles.projectCard} ${className}`} {...props}>
22+
<Card.Body className="d-flex flex-column">
23+
<Card.Title
24+
as="a"
25+
className="text-dark fw-bold"
26+
title={name as string}
27+
target="_blank"
28+
href={link as string}
29+
>
30+
{(name || link) as string}
31+
</Card.Title>
32+
<p className="text-dark opacity-75 mb-3">{summary as string}</p>
33+
<div className="flex-fill mb-3">
34+
<FilePreview className="w-100" path={link as string} />
6835
</div>
69-
)}
7036

71-
<time className="text-dark opacity-75 small" dateTime={new Date(createdAt as number).toJSON()}>
72-
📅 {formatDate(createdAt as number)}
73-
</time>
74-
</Card.Body>
75-
</Card>
76-
),
37+
{sourceLink && (
38+
<div className="d-flex flex-wrap gap-2 mb-3">
39+
<Button
40+
variant="dark"
41+
size="sm"
42+
href={sourceLink as string}
43+
target="_blank"
44+
rel="noreferrer"
45+
>
46+
GitHub
47+
</Button>
48+
<Button
49+
variant="primary"
50+
size="sm"
51+
href={`https://github.dev/${(sourceLink as string).replace('https://github.com/', '')}`}
52+
target="_blank"
53+
rel="noreferrer"
54+
>
55+
GitHub.dev
56+
</Button>
57+
<Button
58+
variant="dark"
59+
size="sm"
60+
href={`https://codespaces.new/${(sourceLink as string).replace('https://github.com/', '')}`}
61+
target="_blank"
62+
rel="noreferrer"
63+
>
64+
Codespaces
65+
</Button>
66+
<Button
67+
variant="warning"
68+
size="sm"
69+
href={`https://gitpod.io/#${sourceLink as string}`}
70+
target="_blank"
71+
rel="noreferrer"
72+
>
73+
GitPod
74+
</Button>
75+
</div>
76+
)}
77+
78+
{createdAtISO && (
79+
<time
80+
suppressHydrationWarning
81+
className="text-dark opacity-75 small"
82+
dateTime={createdAtISO}
83+
>
84+
📅 {createdAtText}
85+
</time>
86+
)}
87+
</Card.Body>
88+
</Card>
89+
);
90+
},
7791
);

0 commit comments

Comments
 (0)