Skip to content

fix(code-browser): guard commit header against invalid commit date#1332

Open
jaso0n0818 wants to merge 1 commit into
entrius:testfrom
jaso0n0818:fix/code-browser-invalid-commit-date
Open

fix(code-browser): guard commit header against invalid commit date#1332
jaso0n0818 wants to merge 1 commit into
entrius:testfrom
jaso0n0818:fix/code-browser-invalid-commit-date

Conversation

@jaso0n0818

Copy link
Copy Markdown

Summary

The repository code browser renders the current commit's relative time with formatDistanceToNow(new Date(currentCommit.date), ...). date-fns throws RangeError: Invalid time value on an Invalid Date, so a malformed or missing commit timestamp from the GitHub API crashes the entire code-browser panel.

This routes the value through a small commitRelativeTime helper that returns '' for an unparseable date instead of throwing, so the commit header degrades gracefully. (Companion to the formatDate hardening in the separate PR for src/utils/format.ts; this is the one direct date-fns call in the code browser that bypasses that util.)

Related Issues

No issue filed; self-contained crash hardening on API-sourced data. Pure logic change — the only visible difference is on malformed input (where it previously crashed), so no before/after media applies per CONTRIBUTING ("Pure logic changes … are exempt").

Type of Change

  • Bug fix
  • New feature
  • Refactor / Enhancement
  • Documentation
  • Other

Testing

npm run lint    # eslint --max-warnings 0: clean
npm run build   # tsc -b && vite build: success
npx prettier --check src/components/repositories/RepositoryCodeBrowser.tsx   # clean

commitRelativeTime('2026-06-14T00:00:00Z') → "in N months" (valid, unchanged); commitRelativeTime('N/A') / missing → '' (was: RangeError crash → now graceful).

Checklist

  • Code follows repository style (eslint + prettier clean)
  • Self-reviewed the diff
  • No unrelated changes
  • Pure logic change — no UI/UX media required

The repository code browser rendered the current commit's relative time with
formatDistanceToNow(new Date(currentCommit.date), ...). date-fns throws
'RangeError: Invalid time value' on an Invalid Date, so a malformed or missing
commit timestamp from the GitHub API crashed the whole code-browser panel.

Route it through a small helper that returns '' for an unparseable date
instead of throwing, so the header degrades gracefully.
@xiao-xiao-mao xiao-xiao-mao Bot added the bug Something isn't working label Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant