-
Notifications
You must be signed in to change notification settings - Fork 2
update rsvp fetch method to avoid erroring #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
boykisserchan
commented
Nov 5, 2025
- no pii for you :trolley:
- bleh
- i am bad at coding
- start caching rsvps and move to local api for fast data
- why wasn't this commited?
- Update rsvp.ts
- Update RSVP.tsx
- rsvp work
- update subtitle
- throw error to catch
- security :thumbup:
- Update src/pages/api/rsvp.ts
- Apply suggestion from @copilot
- install :3
- something something return the erorr
- refactor: update ButtonProps to use ReactNode type for children
- feat: implement background cache updater for RSVP count
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
|
lgtm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
|
lgtm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/pages/api/rsvp.ts
Outdated
| let cached: Cache = { value: null, updated: 0 }; | ||
|
|
||
| // Default cache duration 30 seconds; can be overridden with env var (ms) | ||
| const CACHE_DURATION_MS = Number(process.env.RSVP_CACHE_DURATION_MS) || 30_000; |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Number() on an undefined or empty string environment variable returns NaN, not a falsy value. This means the || fallback won't work as expected. Use parseInt() with a radix or check for NaN explicitly: parseInt(process.env.RSVP_CACHE_DURATION_MS || '30000', 10) or Number(process.env.RSVP_CACHE_DURATION_MS) || 30_000 should be (Number(process.env.RSVP_CACHE_DURATION_MS) || 30_000) with parentheses, but better is: const parsed = parseInt(process.env.RSVP_CACHE_DURATION_MS ?? '', 10); const CACHE_DURATION_MS = isNaN(parsed) ? 30_000 : parsed;
| const CACHE_DURATION_MS = Number(process.env.RSVP_CACHE_DURATION_MS) || 30_000; | |
| const parsedCacheDuration = parseInt(process.env.RSVP_CACHE_DURATION_MS ?? '', 10); | |
| const CACHE_DURATION_MS = isNaN(parsedCacheDuration) ? 30_000 : parsedCacheDuration; |
src/pages/api/rsvp.ts
Outdated
| // initial immediate update (fire-and-forget) | ||
| updateCache().catch((e) => console.error("[rsvp] initial update failed:", e)); | ||
|
|
||
| // schedule periodic updates | ||
| global.__RSVP_CACHE_TIMER__ = setInterval(() => { | ||
| updateCache().catch((e) => console.error("[rsvp] scheduled update failed:", e)); | ||
| }, CACHE_DURATION_MS); |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The module-level initialization code creates a race condition. If multiple requests arrive simultaneously before global.__RSVP_CACHE_TIMER__ is set (line 65), multiple intervals could be created. The timer assignment should happen immediately: global.__RSVP_CACHE_TIMER__ = true; (or a placeholder) before line 62, then reassign to the actual interval on line 65, or use a synchronous check-and-set pattern.
| // initial immediate update (fire-and-forget) | |
| updateCache().catch((e) => console.error("[rsvp] initial update failed:", e)); | |
| // schedule periodic updates | |
| global.__RSVP_CACHE_TIMER__ = setInterval(() => { | |
| updateCache().catch((e) => console.error("[rsvp] scheduled update failed:", e)); | |
| }, CACHE_DURATION_MS); | |
| // Claim the timer slot immediately to prevent race conditions | |
| global.__RSVP_CACHE_TIMER__ = true as any; | |
| // initial immediate update (fire-and-forget) | |
| updateCache().catch((e) => console.error("[rsvp] initial update failed:", e)); | |
| // schedule periodic updates | |
| const interval = setInterval(() => { | |
| updateCache().catch((e) => console.error("[rsvp] scheduled update failed:", e)); | |
| }, CACHE_DURATION_MS); | |
| global.__RSVP_CACHE_TIMER__ = interval; |
src/pages/api/rsvp.ts
Outdated
| if (typeof process !== "undefined" && process.on) { | ||
| process.on("SIGTERM", shutdownRSVPTimer); | ||
| process.on("SIGINT", shutdownRSVPTimer); | ||
| process.on("exit", shutdownRSVPTimer); |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'exit' event does not support asynchronous operations, and handlers should be synchronous. While shutdownRSVPTimer() is synchronous, registering cleanup on 'exit' after 'SIGTERM' and 'SIGINT' is redundant because those signals already trigger the exit event. More importantly, in serverless environments (like Vercel), process event listeners may not behave as expected. Consider removing this line or documenting that it's specifically for local development.
| process.on("exit", shutdownRSVPTimer); | |
| // Removed 'exit' event handler registration; see CodeQL warning. |
| href?: string; | ||
| disable?: boolean; | ||
| children: React.ReactNode; | ||
| children: ReactNode; |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Inconsistent React type import usage. Line 4 uses React.ButtonHTMLAttributes (namespace import), but line 9 now uses ReactNode (named import). For consistency, either use React.ReactNode without the import on line 2, or change line 4 to use a named import like ButtonHTMLAttributes from 'react'. The current mixed approach is valid but inconsistent.