Skip to content

Fix dead code in calculateStreak function to restore grace-period check#8174

Open
nishupr wants to merge 1 commit into
JhaSourav07:mainfrom
nishupr:fix/calculate-dead-grace-period-8117
Open

Fix dead code in calculateStreak function to restore grace-period check#8174
nishupr wants to merge 1 commit into
JhaSourav07:mainfrom
nishupr:fix/calculate-dead-grace-period-8117

Conversation

@nishupr

@nishupr nishupr commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #8117

The if/else block in calculateStreak correctly set todayIndex = -1 when the gap between the last commit and today exceeded the grace period — but a trailing unconditional todayIndex = lastIndex line immediately overwrote that result, making the grace-period rejection completely dead code. Every streak was treated as active regardless of the gap.

Fix: deleted the stray todayIndex = lastIndex line after the if/else block.

Tests: updated 10 tests that called calculateStreak() with no now param — they relied on the buggy overwrite to produce positive streaks against stale 2024-01-xx calendars. Each now passes an explicit now date matching the last day of its calendar, making the test intent clear and independent of the real wall clock.

Pillar

  • 🎨 Pillar 1 — New Theme Design
  • 📐 Pillar 2 — Geometric SVG Improvement
  • 🕐 Pillar 3 — Timezone Logic Optimization
  • 🛠️ Other (Bug fix, refactoring, docs)

Visual Preview

N/A — this is a logic bug fix with no visual output change.

Checklist before requesting a review:

  • I have read the CONTRIBUTING.md file.
  • I have tested these changes locally (localhost:3000/api/streak?user=YOUR_USERNAME).
  • I have run npm run format and npm run lint locally and resolved all errors (CI will fail otherwise).
  • My commits follow the Conventional Commits format (e.g., feat(themes): ..., fix(calculate): ...).
  • I have updated README.md if I added a new theme or URL parameter.
  • I have started the repo.
  • I have made sure that i have only one commit to merge in this PR.
  • The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts).
  • (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.

@vercel

vercel Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Someone is attempting to deploy a commit to the jhasourav07's projects Team on Vercel.

A member of the Team first needs to authorize it.

@retenta-bot

retenta-bot Bot commented Jul 18, 2026

Copy link
Copy Markdown

This pull request addresses a critical bug by removing a line of code that was overwriting the grace-period check in the calculateStreak function. This change is essential for ensuring that users receive accurate streak statuses based on their contributions. Similar decisions have been validated in the past, confirming the importance of this fix. Thank you for your contribution, and I look forward to your updates!

@retenta-bot retenta-bot Bot changed the title fix: remove dead todayIndex overwrite that nullified grace-period check Fix dead code in calculateStreak function to restore grace-period check Jul 18, 2026
@github-actions github-actions Bot added the status:blocked This PR is blocked due to a failing CI check. label Jul 18, 2026
…iod check (JhaSourav07#8117)

The if/else block correctly set todayIndex = -1 when gapDays exceeded
the grace period, but a trailing unconditional line immediately reset it
to lastIndex, making the grace-period rejection dead code. Every streak
was treated as active regardless of the gap.

Fix: deleted the stray todayIndex = lastIndex line after the if/else.

Tests: updated 6 test files whose calculateStreak() calls used hardcoded
2024 dates with no 'now' param — they relied on the buggy overwrite to
produce positive streaks against stale calendars. Each now passes the
correct date so assertions reflect actual intended behaviour.
@nishupr
nishupr force-pushed the fix/calculate-dead-grace-period-8117 branch from 0e37db8 to 4adbdfd Compare July 18, 2026 13:21
@github-actions github-actions Bot removed the status:blocked This PR is blocked due to a failing CI check. label Jul 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Next.js Bundle Size Report (Gzipped Sizes)

✨ No significant bundle size changes detected.

📊 Summary of Totals

Category PR Size Base Size Difference
Total JS 3966.23 KB 3966.23 KB 0 B
Total CSS 330.26 KB 330.26 KB 0 B

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Dead grace-period logic in calculate.ts

1 participant