Skip to content

fix(streak): add .filter(Boolean) guards to aggregate/calculate calendars#6128

Closed
hardik-bhalekar wants to merge 1 commit into
JhaSourav07:mainfrom
hardik-bhalekar:fix/streak-metric-parsing
Closed

fix(streak): add .filter(Boolean) guards to aggregate/calculate calendars#6128
hardik-bhalekar wants to merge 1 commit into
JhaSourav07:mainfrom
hardik-bhalekar:fix/streak-metric-parsing

Conversation

@hardik-bhalekar

Copy link
Copy Markdown

Summary

Adds defensive .filter(Boolean) guards to every array iteration over calendar.weeks and contributionDays in the data-processing pipeline, preventing TypeError: Cannot read properties of null crashes when the GitHub GraphQL API returns sparse or null calendar records.

Problem

The GitHub Contributions GraphQL API occasionally returns null entries inside the weeks array or contributionDays sub-arrays — especially for newly created accounts, accounts with gaps in activity, or during API degradation. The existing code uses .flatMap() and .forEach() on these arrays without null guards, causing runtime crashes that surface as 500 errors on the streak card endpoint.

Changes

lib/github.tsfetchContributionsUncached()

  • Added .filter(Boolean) after (calendar.weeks || []) before .map()
  • Added .filter(Boolean) after contributionDays array before .map()

lib/calculate.ts — Multiple functions

Function Guard Added
calculateStreak() .filter(Boolean) on weeks and contributionDays; added !d.date null-check
calculateMonthlyStats() .filter(Boolean) on weeks and contributionDays
aggregateCalendars() .filter(Boolean) on all 3 weeks/contributionDays iteration loops
calculateWrappedStats() .filter(Boolean) on weeks and contributionDays
normalizeCalendarToTimezone() .filter(Boolean) on calendar.weeks and contributionDays

Why .filter(Boolean)

This is the idiomatic JavaScript/TypeScript pattern for stripping null, undefined, 0, and "" from arrays in a single pass. It's safe here because contribution day objects are always truthy when present, and falsy entries are always invalid API artifacts.

Testing

  • npx tsc --noEmit passes with zero errors
  • Null/undefined entries in weeks or contributionDays are safely skipped
  • Valid contribution data is processed identically to before

@vercel

vercel Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

@hardik-bhalekar is attempting to deploy a commit to the jhasourav07's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hey @hardik-bhalekar! Thanks for your contribution! 🎉

Unfortunately, this PR has been automatically closed because it is not linked to any open issue.

To resolve this, please do the following:

  1. Link a valid open issue by editing your PR description to include a closing keyword (e.g., Fixes #<issue-number>).
  2. Reopen this PR once the link is added.

💡 You can link multiple issues if needed (e.g. Fixes #12, Closes #34).
If you're working on something that doesn't have an issue yet, please open one first and then link it here.

We look forward to reviewing your PR once an issue is linked! 🚀

@github-actions github-actions Bot closed this Jun 20, 2026
@github-actions github-actions Bot added the type:bug Something isn't working as expected label Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant