Skip to content

Commit 1a1fec0

Browse files
committed
fix: update AddressAndTime component to handle client-side time rendering
1 parent 3d3d609 commit 1a1fec0

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

components/footer/address-and-time.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client'
22

33
import { Clock, Map } from 'lucide-react'
4+
import { useEffect, useState } from 'react'
45
import { GrowingUnderline } from '~/components/effects/growing-underline'
56
import { Link } from '~/components/ui/link'
67
// import { Twemoji } from '~/components/ui/twemoji'
@@ -32,7 +33,16 @@ function getTime() {
3233
}
3334

3435
export function AddressAndTime() {
35-
const { time, diff } = getTime()
36+
// NOTE:
37+
// This component depends on the visitor's timezone. If we render it on the server,
38+
// the server timezone will likely differ and cause a hydration mismatch (React #418).
39+
// So we only compute time after the client has mounted.
40+
const [timeInfo, setTimeInfo] = useState<{ time: string; diff: string } | null>(null)
41+
42+
useEffect(() => {
43+
setTimeInfo(getTime())
44+
}, [])
45+
3646
return (
3747
<div className="space-y-2 py-1.5 text-gray-800 dark:text-gray-200">
3848
<div className="flex items-center gap-2">
@@ -50,7 +60,8 @@ export function AddressAndTime() {
5060
<Clock className="h-5 w-5" />
5161
<Link href={TIME_IS}>
5262
<GrowingUnderline className="font-medium" data-umami-event="footer-time">
53-
{time} <span className="text-gray-500 dark:text-gray-400">({diff})</span>
63+
{timeInfo?.time ?? '--:--'}{' '}
64+
<span className="text-gray-500 dark:text-gray-400">({timeInfo?.diff ?? '...'})</span>
5465
</GrowingUnderline>
5566
</Link>
5667
</div>

0 commit comments

Comments
 (0)