perf: Implement Next.js Edge Timeout Racer with Stale Cache fallback#5288
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a timeout wrapper around GitHub contribution fetches so requests don’t hang indefinitely and the system can fall back to stale cached data, while also improving related warning messages.
Changes:
- Introduces a
Promise.race-based timeout aroundfetchContributionsUncachedcalls. - Uses the timeout-wrapped loader in both forced-refresh and cache
getOrSetpaths. - Updates warning messages (including fixing a typo) to mention timeouts.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const timeoutPromise = (ms: number) => | ||
| new Promise<never>((_, reject) => { | ||
| const timer = setTimeout(() => reject(new Error('TimeoutRacer')), ms); | ||
| // Unref node timer if possible to prevent hanging tests | ||
| if (timer && typeof timer.unref === 'function') { | ||
| timer.unref(); | ||
| } | ||
| }); | ||
|
|
||
| const loadWithTimeout = async () => { | ||
| return Promise.race([load(), timeoutPromise(4000)]); | ||
| }; |
|
|
||
| const timeoutPromise = (ms: number) => | ||
| new Promise<never>((_, reject) => { | ||
| const timer = setTimeout(() => reject(new Error('TimeoutRacer')), ms); |
| }); | ||
|
|
||
| const loadWithTimeout = async () => { | ||
| return Promise.race([load(), timeoutPromise(4000)]); |
|
@MasterJi27 is attempting to deploy a commit to the jhasourav07's projects Team on Vercel. A member of the Team first needs to authorize it. |
23a8bc5 to
b5d4467
Compare
|
🚨 Hey @MasterJi27, the CI Pipeline is failing on this PR and it has been marked as 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 passes2. Auto-fix common issues: npm run format # Auto-fix formatting with Prettier
npm run lint -- --fix # Auto-fix lint errors where possible3. Check the full failure log here: Once you push a fix and the CI passes, the |
e794ad9 to
4a7bfc6
Compare
Aamod-Dev
left a comment
There was a problem hiding this comment.
Thanks for putting this together. The code looks clean and solves the issue effectively.
I'm happy to approve this. Great job!
|
🎉 Congratulations @MasterJi27! Your PR has been successfully merged. 🚀 Thank you for contributing to CommitPulse. Your work helps us build a better tool for the community.
Keep building! 💻✨ |
|
Review Summary |
Resolves #5240. Implements a 4-second timeout race using Promise.race, returning stale cached data with isOfflineFallback: true on timeout or fetch failures.