fix(header): 右上角日期客户端实时刷新,避免 SSG 冻结 build 时刻#357
Draft
longsizhuo wants to merge 2 commits into
Draft
Conversation
Header 右侧日期原先在 server component 用 new Date() 渲染,SSG/ISR 下会被冻结在 build 时刻,导致线上长期显示陈旧日期。改为客户端组件 LiveDate,沿用 LiveEditionLabel 的固定悉尼时区 + 每秒刷新模式, 首帧用 server 时间戳保证 hydration 一致。
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Date.now() 被 react-hooks/purity 规则判为 render 期不纯调用, 改用与原实现一致的 new Date().getTime()。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
线上 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已验证的模式:initialTimestamp渲染,保证 hydration 一致Australia/Sydney)+ 每秒刷新,避免再被 build 时刻冻住Header 改为传入时间戳并渲染
<LiveDate />,移除 server 端的formattedDate计算。🤖 Generated with Claude Code
Generated by Claude Code