Skip to content

fix(header): 右上角日期客户端实时刷新,避免 SSG 冻结 build 时刻#357

Draft
longsizhuo wants to merge 2 commits into
mainfrom
claude/youthful-carson-m6yqze
Draft

fix(header): 右上角日期客户端实时刷新,避免 SSG 冻结 build 时刻#357
longsizhuo wants to merge 2 commits into
mainfrom
claude/youthful-carson-m6yqze

Conversation

@longsizhuo

Copy link
Copy Markdown
Member

问题

线上 https://involutionhell.com/zh 右上角日期长期停留在陈旧日期(如 May 25, 2026),不会随时间更新。

根因

Header.tsx 是 server component,右侧日期用 new Date().toLocaleDateString(...) 在渲染时计算。首页走 SSG/ISR,该日期被冻结在 build 时刻,运行时不会更新。左侧 LiveEditionLabel 之所以正常,是因为它是 client component,靠 setInterval 每秒刷新。

修复

新增 client component LiveDate,沿用 LiveEditionLabel 已验证的模式:

  • 首帧用 server 传入的 initialTimestamp 渲染,保证 hydration 一致
  • 挂载后固定悉尼时区(Australia/Sydney)+ 每秒刷新,避免再被 build 时刻冻住

Header 改为传入时间戳并渲染 <LiveDate />,移除 server 端的 formattedDate 计算。

🤖 Generated with Claude Code


Generated by Claude Code

Header 右侧日期原先在 server component 用 new Date() 渲染,SSG/ISR
下会被冻结在 build 时刻,导致线上长期显示陈旧日期。改为客户端组件
LiveDate,沿用 LiveEditionLabel 的固定悉尼时区 + 每秒刷新模式,
首帧用 server 时间戳保证 hydration 一致。
@vercel

vercel Bot commented Jun 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
involutionhell-github-io Canceled Canceled Jun 17, 2026 9:48am
website-preview Ready Ready Preview, Comment Jun 17, 2026 9:48am

Date.now() 被 react-hooks/purity 规则判为 render 期不纯调用,
改用与原实现一致的 new Date().getTime()。
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.

2 participants