-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ref: Use optional chaining wherever possible #17017
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
size-limit report 📦
|
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.
Bug: Refactor Changes `ctx` Assignment and Call Behavior
The refactoring of the ctx
assignment introduces two behavioral changes:
- Fallback and type guarantee:
ctx
is no longer guaranteed to be an object. Previously, it defaulted to{}
whenvercelRequestContextGlobal.get()
returned a falsy value. Now,ctx
will beundefined
or the falsy value returned byget()
, which can alter the subsequentctx?.waitUntil
check. - Function call count: The original code called
vercelRequestContextGlobal.get()
twice when it returned a truthy value, while the new code calls it only once. This changes behavior ifget()
has side effects or returns different values on subsequent calls.
packages/core/src/utils/vercelWaitUntil.ts#L20-L21
sentry-javascript/packages/core/src/utils/vercelWaitUntil.ts
Lines 20 to 21 in 250d7fc
const ctx = vercelRequestContextGlobal?.get?.(); |
Was this report helpful? Give feedback by reacting with 👍 or 👎
@@ -18,8 +18,7 @@ export function vercelWaitUntil(task: Promise<unknown>): void { | |||
// @ts-expect-error This is not typed | |||
GLOBAL_OBJ[Symbol.for('@vercel/request-context')]; | |||
|
|||
const ctx = | |||
vercelRequestContextGlobal?.get && vercelRequestContextGlobal.get() ? vercelRequestContextGlobal.get() : {}; | |||
const ctx = vercelRequestContextGlobal?.get?.(); |
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.
is this identical or should it rather be
const ctx = vercelRequestContextGlobal?.get?.(); | |
const ctx = vercelRequestContextGlobal?.get?.() ?? {} |
?
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.
it's not identical, but how this is used is:
if (ctx?.waitUntil) {
ctx.waitUntil(task);
}
which should work the same I'd say?
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.
ah ok, sorry, should have checked the usage. Makes sense!
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.
Nice!
A future version of eslint flagged & auto-fixed these, extracting this out for easier review.