Skip to content

feat: implement SWR cache-control headers and resolve edge runtime compilation errors (#4152)#4746

Closed
thakurakanksha288 wants to merge 11 commits into
JhaSourav07:mainfrom
thakurakanksha288:feat/swr-cache-optimization
Closed

feat: implement SWR cache-control headers and resolve edge runtime compilation errors (#4152)#4746
thakurakanksha288 wants to merge 11 commits into
JhaSourav07:mainfrom
thakurakanksha288:feat/swr-cache-optimization

Conversation

@thakurakanksha288

@thakurakanksha288 thakurakanksha288 commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

🛠️ Description

close #4152

This PR implements fine-tuned Stale-While-Revalidate (SWR) Cache-Control headers for the dynamic SVG generation routes inside app/api/streak/route.ts.

Without proper cache directives, high burst traffic from embedded GitHub Profile README views forces repeated, expensive upstream GraphQL API queries. This implementation configures edge networks (Vercel/Cloudflare) to instantaneously serve cached monolith SVGs while asynchronously refreshing data fields in the background.

Additionally, this PR addresses critical compilation blocks and Edge runtime errors discovered during local environment verification.


🚀 Changes Implemented

  • SWR Cache Header Strategies: Configured custom CDN cache metrics utilizing maximum age constraints mapped dynamically against daily UTC/local midnight expirations (public, max-age=3600, s-maxage=${secondsToMidnight}, stale-while-revalidate=86400, must-revalidate).
  • Web Crypto Standardization: Swapped the standard Node.js native crypto module for standard crypto.subtle.digest calls, successfully eliminating Next.js Serverless/Edge environment compilation warnings.
  • Syntax & Structural Alignment: Fixed broken block nesting boundaries between GET handlers and error-response mapping handlers.
  • Historical Query Caching: Forced long-lived immutable cache headers (public, s-maxage=31536000, immutable) for past year analytics queries since historical commit distributions never change.

🧪 Verification & Local Testing

  1. Verified server stability locally via npm run dev with Next.js compiling cleanly without import squiggles.
  2. Verified runtime performance via curl queries:
    curl -I "http://localhost:3000/api/streak?user=thakurakanksha288"
    
    closes #4152
    

@vercel

vercel Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

@thakurakanksha288 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 status:blocked This PR is blocked due to a failing CI check. label Jun 7, 2026
@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

🚨 Hey @thakurakanksha288, 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 removed the status:blocked This PR is blocked due to a failing CI check. label Jun 7, 2026
@thakurakanksha288

Copy link
Copy Markdown
Contributor Author

Hi @JhaSourav07,

I have updated the streak API route (app/api/streak/route.ts) to fix the failing CI checks.

🛠️ What changed?
Cache Headers Re-aligned: Updated the Cache-Control strings across different views (including historical years and refresh overrides) to perfectly match the literal strings expected by the test suite.

Web Crypto Environment Fallback: Added a lightweight string hashing fallback mechanism to generateETag so it no longer breaks or throws runtime errors in simulated Jest/Vitest Node testing environments where crypto.subtle might be undefined.

Prettier Mismatches Cleaned: Fixed nested multi-line indentation layouts to fully conform with the repository's strict formatting standards.

The test suite and Prettier check are now passing perfectly. Ready for your review and merge! 🚀

Thanks!

@Aamod-Dev Aamod-Dev added mentor:Aamod007 GSSoC 2026 level:advanced Complex contributions involving architecture, optimization, or significant feature work quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. labels Jun 7, 2026
@github-actions github-actions Bot added the type:feature New features, additions, or enhancements label Jun 8, 2026
@thakurakanksha288

Copy link
Copy Markdown
Contributor Author

hi @JhaSourav07, kindly check once again.

@github-actions github-actions Bot added the status:blocked This PR is blocked due to a failing CI check. label Jun 9, 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.

Appreciate you taking the time to submit this PR. I went through the implementation and the approach looks solid.

Everything looks good. Approving this now.

@thakurakanksha288 thakurakanksha288 closed this by deleting the head repository Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:needs-rebase GSSoC 2026 level:advanced Complex contributions involving architecture, optimization, or significant feature work mentor:Aamod007 quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. status:blocked This PR is blocked due to a failing CI check. type:feature New features, additions, or enhancements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: <short description of the feature>## 🚀 [Optimization]: Implement Stale-While-Revalidate (SWR) Cache-Control Headers for SVG Generation Routes

3 participants