Skip to content

refactor(calculate): replace JSON.parse/stringify anti-pattern with structuredClone() in aggregateCalendars#5025

Merged
JhaSourav07 merged 3 commits into
JhaSourav07:mainfrom
ChetanSenta:refactor/aggregate-calendars-structured-clone
Jun 12, 2026
Merged

refactor(calculate): replace JSON.parse/stringify anti-pattern with structuredClone() in aggregateCalendars#5025
JhaSourav07 merged 3 commits into
JhaSourav07:mainfrom
ChetanSenta:refactor/aggregate-calendars-structured-clone

Conversation

@ChetanSenta

Copy link
Copy Markdown
Contributor

Description

Fixes #5019

Pillar

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

Visual Preview

No visual change. This is a pure internal refactor in lib/calculate.ts.

What this PR does

Replaces the JSON.parse(JSON.stringify(baseCalendar)) deep clone
anti-pattern in aggregateCalendars() with structuredClone().

structuredClone() is native in Node 18+ (CommitPulse requires Node 18+),
faster (no JSON string intermediate), and correctly handles edge cases
that JSON serialization drops silently (undefined values, Date objects).

Before vs After

// Before (anti-pattern — silent data loss for undefined/Date fields):
const aggregatedBase = JSON.parse(
JSON.stringify(baseCalendar)
) as ContributionCalendar;

// After (idiomatic Node 18+ — correct, fast, readable):
const aggregatedBase = structuredClone(baseCalendar);

Changes

File Change
lib/calculate.ts 1-line change: JSON.parse/stringify → structuredClone()
lib/calculate.test.ts 5 new tests: mutation isolation, reference independence, optional field preservation

Why this is safe

Current ContributionCalendar has no Date or undefined fields — so
JSON.parse/stringify was not silently dropping data today. But the
refactor prevents a future silent bug if schema changes add such fields.
All 5 new tests verify the deep clone contract is correctly maintained.

Checklist before requesting a review:

  • I have read the CONTRIBUTING.md file.
  • I have tested these changes locally.
  • I have run npm run format and npm run lint locally and resolved all errors.
  • My commits follow the Conventional Commits format.
  • I have updated README.md if I added a new theme or URL parameter.
  • I have starred 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.
  • (Recommended) I joined the CommitPulse Discord server.

@vercel

vercel Bot commented Jun 9, 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.

@github-actions github-actions Bot added the type:refactor Code changes that neither fix a bug nor add a feature label Jun 9, 2026
@Aamod-Dev Aamod-Dev added level:intermediate Moderate complexity tasks quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. GSSoC 2026 mentor:Aamod007 labels Jun 11, 2026

@Aamod-Dev Aamod-Dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent refactoring! Replacing the JSON.parse/stringify serialization hack with structuredClone() will definitely improve performance during calendar aggregation. Approving!

@Aamod-Dev Aamod-Dev added the level:beginner Small changes Usually isolated fixes or simple UI/text updates. label Jun 11, 2026

@Aamod-Dev Aamod-Dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together. The changes are clean and the logic looks sound. The new additions are clean and integrate nicely with the existing codebase. This is good to go.

@Aamod-Dev Aamod-Dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. I've taken a look at the changes and everything seems to align with what we need here.

I am adding the quality:exceptional label because the implementation not only solves the core issue but goes beyond by effectively handling edge cases, tests, or reducing technical debt. Great work going above and beyond!

No concerns from my end. Approved.

@Aamod-Dev Aamod-Dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. I went through the changes and the overall approach looks good, but there are a few issues that should be addressed before this can be merged. Most of the concerns are related to correctness and maintainability.

  • There are merge conflicts with the base branch. Please resolve them to ensure existing functionality isn't broken.

Once these issues are addressed, I'll be happy to take another look. Thanks again for the contribution.

@Aamod-Dev Aamod-Dev removed the level:beginner Small changes Usually isolated fixes or simple UI/text updates. label Jun 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚨 Hey @ChetanSenta, the CI Pipeline is failing on this PR and it has been marked as status:blocked.

Please fix the issues before this can be reviewed. Here's how:

1. Run checks locally before pushing:

npm run format:check   # Check Prettier formatting
npm run lint           # Run ESLint
npm run typecheck      # TypeScript type check
npm run test           # Run unit tests (Vitest)
npm run build          # Verify production build passes

2. Auto-fix common issues:

npm run format         # Auto-fix formatting with Prettier
npm run lint -- --fix  # Auto-fix lint errors where possible

3. Check the full failure log here:
👉 View CI Run

Once you push a fix and the CI passes, the status:blocked label will be removed automatically. 💪

@github-actions github-actions Bot added the status:blocked This PR is blocked due to a failing CI check. label Jun 12, 2026

@Aamod-Dev Aamod-Dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates! The overall approach looks good, but the CI pipeline (\Format · Lint · Typecheck · Test) is currently failing. Please run
pm run test\ and
pm run lint\ locally to fix the issues. Let me know once it's green!

@Aamod-Dev Aamod-Dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. The overall approach looks good, but the CI pipeline is currently failing. Please run the checks (like npm run format, npm run lint, and npm run test) locally to identify and fix the issues. Let me know once it's green!

@github-actions github-actions Bot removed the status:blocked This PR is blocked due to a failing CI check. label Jun 12, 2026
@ChetanSenta ChetanSenta requested a review from Aamod-Dev June 12, 2026 06:41
@ChetanSenta

Copy link
Copy Markdown
Contributor Author

Thanks for the contribution. The overall approach looks good, but the CI pipeline is currently failing. Please run the checks (like npm run format, npm run lint, and npm run test) locally to identify and fix the issues. Let me know once it's green!

ok

@Aamod-Dev Aamod-Dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the CI pipeline! Approving.

@JhaSourav07 JhaSourav07 added the gssoc:approved PR has been reviewed and accepted for valid contribution points label Jun 12, 2026
@JhaSourav07 JhaSourav07 merged commit ff92476 into JhaSourav07:main Jun 12, 2026
5 of 6 checks passed
@github-actions github-actions Bot added this to the GSSoC 2026 milestone Jun 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Congratulations @ChetanSenta! Your PR has been successfully merged. 🚀

Thank you for contributing to CommitPulse. Your work helps us build a better tool for the community.

⚠️ Important for GSSoC Contributors:
You are strictly advised to join our Discord Server as it is mandatory for all GSSoC participants. All important announcements, point claims, and community discussions happen there.

Keep building! 💻✨

@JhaSourav07 JhaSourav07 added gssoc:approved PR has been reviewed and accepted for valid contribution points and removed gssoc:approved PR has been reviewed and accepted for valid contribution points labels Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved PR has been reviewed and accepted for valid contribution points gssoc:needs-rebase GSSoC 2026 level:intermediate Moderate complexity tasks mentor:Aamod007 quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. type:refactor Code changes that neither fix a bug nor add a feature

Projects

None yet

3 participants