[PR #1843] [MERGED] fix(staffml): derive PaperCitationCard year from buildDate, not new Date() #30947

Closed
opened 2026-06-21 20:35:27 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/harvard-edge/cs249r_book/pull/1843
Author: @farhan523
Created: 6/6/2026
Status: Merged
Merged: 6/10/2026
Merged by: @profvjreddi

Base: devHead: fix/papercitation-deterministic-year


📝 Commits (1)

  • d7a7c38 fix(staffml): derive PaperCitationCard year from buildDate, not new Date()

📊 Changes

2 files changed (+81 additions, -6 deletions)

View changed files

interviews/staffml/src/__tests__/paper-citation-card.test.tsx (+66 -0)
📝 interviews/staffml/src/components/PaperCitationCard.tsx (+15 -6)

📄 Description

Summary

The BibTeX entry in PaperCitationCard took its year from new Date().getFullYear() — the render-time year on the client. With Next's static export the HTML is generated at build time and hydrates on the client whenever the user visits, so server (build) and client (hydrate) could disagree on the year:

  • around midnight UTC on Dec 31 / Jan 1, OR
  • any time the site is viewed in a year after the build year (i.e. always, eventually).

Hydration mismatch warning either way, and the wrong anchor for a citation regardless — the year in a software citation should be the release year, not the year the reader happened to view the page.

Changes

  • Make buildDate required on PaperCitationCardProps. The only call site at app/about/page.tsx already passes it from BUILD_DATE in lib/stats, so this is a type-level alignment with the existing real-world usage.
  • Derive the BibTeX year via new Date(buildDate).getUTCFullYear() so the year matches the build server's UTC reference regardless of viewer timezone.
  • buildDateLabel simplifies: no buildDate ? ... : null ternary, just the formatted string. The && short-circuit at the render site is now redundant but harmless — left as defense-in-depth.

Out of scope

The displayed buildDateLabel still uses toLocaleDateString with no timezone option, which CAN mismatch on a build like 2026-04-22T03:00:00Z viewed in PT (renders "April 22, 2026" on the build server, "April 21, 2026" on a PT client). That's a separate, smaller hydration concern with a UX trade-off (UTC vs viewer's local date) — happy to file a follow-up if it's worth fixing.

Test plan

  • npx vitest run → 60/60 individual cases (was 57 on dev; +3 new for the year derivation, including a clock-mock test that catches future regressions to new Date()).
  • npx tsc --noEmit → unchanged from dev baseline (the 2 pre-existing katex / js-quantities errors are env-local).
  • Manual: open /about, expand "Cite this release", confirm the BibTeX year matches BUILD_DATE's UTC year.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/harvard-edge/cs249r_book/pull/1843 **Author:** [@farhan523](https://github.com/farhan523) **Created:** 6/6/2026 **Status:** ✅ Merged **Merged:** 6/10/2026 **Merged by:** [@profvjreddi](https://github.com/profvjreddi) **Base:** `dev` ← **Head:** `fix/papercitation-deterministic-year` --- ### 📝 Commits (1) - [`d7a7c38`](https://github.com/harvard-edge/cs249r_book/commit/d7a7c3841ebadcd9d5a37b0ce06c5941a101f4eb) fix(staffml): derive PaperCitationCard year from buildDate, not `new Date()` ### 📊 Changes **2 files changed** (+81 additions, -6 deletions) <details> <summary>View changed files</summary> ➕ `interviews/staffml/src/__tests__/paper-citation-card.test.tsx` (+66 -0) 📝 `interviews/staffml/src/components/PaperCitationCard.tsx` (+15 -6) </details> ### 📄 Description ## Summary The BibTeX entry in `PaperCitationCard` took its year from `new Date().getFullYear()` — the *render-time* year on the client. With Next's static export the HTML is generated at build time and hydrates on the client whenever the user visits, so server (build) and client (hydrate) could disagree on the year: - around midnight UTC on Dec 31 / Jan 1, OR - any time the site is viewed in a year after the build year (i.e. always, eventually). Hydration mismatch warning either way, and the wrong anchor for a citation regardless — the year in a software citation should be the release year, not the year the reader happened to view the page. ### Changes - **Make `buildDate` required** on `PaperCitationCardProps`. The only call site at [`app/about/page.tsx`](src/app/about/page.tsx#L70) already passes it from `BUILD_DATE` in `lib/stats`, so this is a type-level alignment with the existing real-world usage. - **Derive the BibTeX year** via `new Date(buildDate).getUTCFullYear()` so the year matches the build server's UTC reference regardless of viewer timezone. - `buildDateLabel` simplifies: no `buildDate ? ... : null` ternary, just the formatted string. The `&&` short-circuit at the render site is now redundant but harmless — left as defense-in-depth. ### Out of scope The displayed `buildDateLabel` still uses `toLocaleDateString` with no timezone option, which CAN mismatch on a build like `2026-04-22T03:00:00Z` viewed in PT (renders \"April 22, 2026\" on the build server, \"April 21, 2026\" on a PT client). That's a separate, smaller hydration concern with a UX trade-off (UTC vs viewer's local date) — happy to file a follow-up if it's worth fixing. ## Test plan - [x] `npx vitest run` → 60/60 individual cases (was 57 on dev; +3 new for the year derivation, including a clock-mock test that catches future regressions to `new Date()`). - [x] `npx tsc --noEmit` → unchanged from dev baseline (the 2 pre-existing `katex` / `js-quantities` errors are env-local). - [ ] Manual: open `/about`, expand \"Cite this release\", confirm the BibTeX year matches `BUILD_DATE`'s UTC year. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-06-21 20:35:27 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/cs249r_book#30947