[PR #1911] [MERGED] fix(staffml): format Footer build date in UTC to avoid hydration mismatch #36526

Closed
opened 2026-07-16 00:25:50 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

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

Base: devHead: fix/footer-hydration-utc


📝 Commits (1)

  • 1a1f247 fix(staffml): format Footer build date in UTC to avoid hydration mismatch

📊 Changes

2 files changed (+61 additions, -0 deletions)

View changed files

interviews/staffml/src/__tests__/footer-build-label.test.tsx (+52 -0)
📝 interviews/staffml/src/components/Footer.tsx (+9 -0)

📄 Description

Summary

Footer rendered new Date(BUILD_DATE).toLocaleDateString(\"en-US\", {...}) without a timeZone option, so the build date formatted in the runtime's local TZ. With Next's static export the HTML is generated at build time on the build server (UTC in CI) and hydrates on the client whenever the user visits. Near day/year boundaries the two TZs disagree:

BUILD_DATE = \"2026-12-31T23:30:00Z\"
  build server (UTC): \"Dec 31, 2026\"
  client in UTC+1:    \"Jan 1, 2027\"

That's both a hydration-mismatch warning and a wrong label — the build is from Dec 31 UTC, not Jan 1 in the viewer's TZ.

Changes

  • Add timeZone: \"UTC\" to the toLocaleDateString options so the label reflects the canonical build instant.
  • Inline comment documents the trap so a future "cleanup" doesn't reintroduce it.

This is the matching fix for the same pattern shipped in PR #1843 for PaperCitationCard.

Test plan

  • npx vitest run → 128/128 across 23 files passing (was already green; +2 new cases on the new Footer test file).
  • npx tsc --noEmit → clean.
  • Manual: change your system clock to a UTC+N timezone and load a content-style route (/about, /contribute) — the footer's Vault v... · <Month> <Day>, <Year> should match the BUILD_DATE in UTC, not your local date.

Test coverage

The regression test mocks @/lib/stats with BUILD_DATE = 2025-01-01T01:00:00Z (Jan 1 2025 UTC, but Dec 31 2024 in PT) and asserts the label reads "Jan 1, 2025" even when vi.setSystemTime puts "now" in a completely different year. If the formatting ever regresses to use the runtime clock or the runtime TZ, both tests fail immediately.


🔄 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/1911 **Author:** [@farhan523](https://github.com/farhan523) **Created:** 6/28/2026 **Status:** ✅ Merged **Merged:** 7/10/2026 **Merged by:** [@profvjreddi](https://github.com/profvjreddi) **Base:** `dev` ← **Head:** `fix/footer-hydration-utc` --- ### 📝 Commits (1) - [`1a1f247`](https://github.com/harvard-edge/cs249r_book/commit/1a1f24788c76efd6815d7ed992e4fdf8f165ed9e) fix(staffml): format Footer build date in UTC to avoid hydration mismatch ### 📊 Changes **2 files changed** (+61 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `interviews/staffml/src/__tests__/footer-build-label.test.tsx` (+52 -0) 📝 `interviews/staffml/src/components/Footer.tsx` (+9 -0) </details> ### 📄 Description ## Summary `Footer` rendered `new Date(BUILD_DATE).toLocaleDateString(\"en-US\", {...})` without a `timeZone` option, so the build date formatted in the runtime's local TZ. With Next's static export the HTML is generated at build time on the build server (UTC in CI) and hydrates on the client whenever the user visits. Near day/year boundaries the two TZs disagree: ``` BUILD_DATE = \"2026-12-31T23:30:00Z\" build server (UTC): \"Dec 31, 2026\" client in UTC+1: \"Jan 1, 2027\" ``` That's both a hydration-mismatch warning and a wrong label — the build *is* from Dec 31 UTC, not Jan 1 in the viewer's TZ. ### Changes - Add `timeZone: \"UTC\"` to the `toLocaleDateString` options so the label reflects the canonical build instant. - Inline comment documents the trap so a future \"cleanup\" doesn't reintroduce it. This is the matching fix for the same pattern shipped in [PR #1843](https://github.com/harvard-edge/cs249r_book/pull/1843) for `PaperCitationCard`. ## Test plan - [x] `npx vitest run` → 128/128 across 23 files passing (was already green; +2 new cases on the new Footer test file). - [x] `npx tsc --noEmit` → clean. - [ ] Manual: change your system clock to a UTC+N timezone and load a content-style route (`/about`, `/contribute`) — the footer's `Vault v... · <Month> <Day>, <Year>` should match the BUILD_DATE in UTC, not your local date. ### Test coverage The regression test mocks `@/lib/stats` with `BUILD_DATE = 2025-01-01T01:00:00Z` (Jan 1 2025 UTC, but Dec 31 2024 in PT) and asserts the label reads \"Jan 1, 2025\" *even when* `vi.setSystemTime` puts \"now\" in a completely different year. If the formatting ever regresses to use the runtime clock or the runtime TZ, both tests fail immediately. --- <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-07-16 00:25:50 -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#36526