Server-render entry word count, read time and relative dates - #1663
Conversation
|
ⓘ Your Qodo trial ends soon. Ask your workspace admin to set up billing to keep reviews running after the trial. Manage billing |
Code Review by Qodo
1. Internal modules mocked with vi.mock
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe change removes SSR placeholders for entry statistics and relative time labels. Word counts and read times are derived during render. ChangesSSR entry metadata
Time label SSR and hydration
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The PR moves entry statistics and relative dates into server-rendered output while preserving absolute-date behavior; no actionable merge-blocking risk remains beyond normal checks and review. Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Some tools did not complete. Review the errors below. 🔧 ESLint
ESLint install failed: private package registry requires authentication. Disable ESLint in CodeRabbit settings or use public packages. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoSSR-render entry stats and relative TimeLabel text
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5dfd2ec11e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const [display, setDisplay] = useState<string | null>(() => { | ||
| if (mode === "fullRelative") return dateToFullRelative(created); | ||
| if (mode === "relative") return dateToRelative(created); | ||
| return null; |
There was a problem hiding this comment.
Force a post-hydration relative-date update
When cached server HTML is stale, or the timestamp crosses a formatting boundary before hydration, this initializer gives the client the new relative value while the DOM still contains the server value. Because the span uses suppressHydrationWarning, React does not patch that mismatched text during hydration, and the mount effect then calls setDisplay with the value already held in state, so it can bail out without correcting the DOM. The label can consequently retain the stale server text until the relative string changes again, potentially for days or months; ensure the post-mount correction causes an actual state transition.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed and fixed in ea33c80, with the mechanism exactly as described: the client initializer already held the corrected value, so the mount effect's setDisplay bailed out on state equality while suppressHydrationWarning had left the server text in the DOM. The initializer is now server-only (typeof window guard), so the client starts at null and the mount effect is always a real state transition whose vdom diff writes the text node. Added the hydration spec you asked for: server HTML rendered at T, hydrated at T+25h with fake timers, asserting the DOM ends on the client value. Verified the spec fails against the previous initializer and passes with the guard.
Code Review by Qodo
1.
|
…rd count to utils
Closes #1662
The word count, read time and relative dates were the last visual changes on a post page: server HTML carried "0", "0 min" and a UTC datetime, which flipped to real values only after hydration (~4.4s in lab runs, the final visually-complete step in WPT
260824_97_3).entry-page-listen.tsx:wordCount/readTimebecomeuseMemoderivations ofentry.body(pure, available server-side), replacinguseState(0)+useMount.countWordsis exported for the spec.TimeLabel: relative modes now initializedisplaywith the computed relative form, so SSR emits "3d" instead of the UTC string. Relative forms are differences of two instants and timezone-independent;mode="absolute"keeps the UTC-first-paint contract since a local format depends on the viewer's timezone. The existingsuppressHydrationWarningabsorbs the boundary case where an edge-cached page's SSR value is one unit stale until the mount effect corrects it.renderToString(no effects, like the server): the stats render real values and relative TimeLabels render the relative form. Verified the pins fail against the previous implementation.useAiAssistandi18next.languageto the global mocks (the component under test needs both at render time).Summary by CodeRabbit