Skip to content

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

Merged
merged 2 commits into from
Jul 15, 2025

Conversation

mydea
Copy link
Member

@mydea mydea commented Jul 15, 2025

A future version of eslint flagged & auto-fixed these, extracting this out for easier review.

@mydea mydea requested review from Lms24 and chargome July 15, 2025 11:09
@mydea mydea self-assigned this Jul 15, 2025
@mydea mydea requested review from a team as code owners July 15, 2025 11:09
Copy link
Contributor

github-actions bot commented Jul 15, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.88 kB -0.02% -3 B 🔽
@sentry/browser - with treeshaking flags 22.35 kB -0.02% -4 B 🔽
@sentry/browser (incl. Tracing) 39.75 kB -0.02% -6 B 🔽
@sentry/browser (incl. Tracing, Replay) 77.86 kB -0.02% -15 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.6 kB -0.02% -12 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 82.57 kB -0.02% -13 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 94.67 kB -0.02% -14 B 🔽
@sentry/browser (incl. Feedback) 40.57 kB -0.02% -7 B 🔽
@sentry/browser (incl. sendFeedback) 28.56 kB -0.01% -1 B 🔽
@sentry/browser (incl. FeedbackAsync) 33.45 kB -0.02% -6 B 🔽
@sentry/react 25.6 kB -0.03% -6 B 🔽
@sentry/react (incl. Tracing) 41.72 kB -0.02% -7 B 🔽
@sentry/vue 28.31 kB -0.02% -3 B 🔽
@sentry/vue (incl. Tracing) 41.53 kB -0.01% -4 B 🔽
@sentry/svelte 23.9 kB -0.02% -3 B 🔽
CDN Bundle 25.18 kB -0.02% -3 B 🔽
CDN Bundle (incl. Tracing) 39.43 kB -0.02% -6 B 🔽
CDN Bundle (incl. Tracing, Replay) 75.42 kB -0.03% -16 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 80.9 kB -0.02% -15 B 🔽
CDN Bundle - uncompressed 73.52 kB -0.03% -18 B 🔽
CDN Bundle (incl. Tracing) - uncompressed 116.95 kB -0.04% -37 B 🔽
CDN Bundle (incl. Tracing, Replay) - uncompressed 231.11 kB -0.04% -72 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 243.92 kB -0.03% -72 B 🔽
@sentry/nextjs (client) 43.73 kB -0.04% -17 B 🔽
@sentry/sveltekit (client) 40.19 kB -0.01% -4 B 🔽
@sentry/node 167.69 kB +0.01% +3 B 🔺
@sentry/node - without tracing 100.33 kB -0.01% -7 B 🔽
@sentry/aws-serverless 128.47 kB -0.02% -15 B 🔽

View base workflow run

Copy link

@cursor cursor bot left a 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:

  1. Fallback and type guarantee: ctx is no longer guaranteed to be an object. Previously, it defaulted to {} when vercelRequestContextGlobal.get() returned a falsy value. Now, ctx will be undefined or the falsy value returned by get(), which can alter the subsequent ctx?.waitUntil check.
  2. 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 if get() has side effects or returns different values on subsequent calls.

packages/core/src/utils/vercelWaitUntil.ts#L20-L21

const ctx = vercelRequestContextGlobal?.get?.();

Fix in CursorFix in Web


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?.();
Copy link
Member

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

Suggested change
const ctx = vercelRequestContextGlobal?.get?.();
const ctx = vercelRequestContextGlobal?.get?.() ?? {}

?

Copy link
Member Author

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?

Copy link
Member

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!

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Nice!

@mydea mydea merged commit 004072e into develop Jul 15, 2025
168 checks passed
@mydea mydea deleted the fn/use-more-optional-chaining branch July 15, 2025 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants