Skip to content

feat(core): Only check for native fetch in browser - #22893

Open
mydea wants to merge 1 commit into
developfrom
fn/native-fetch-check
Open

feat(core): Only check for native fetch in browser#22893
mydea wants to merge 1 commit into
developfrom
fn/native-fetch-check

Conversation

@mydea

@mydea mydea commented Jul 31, 2026

Copy link
Copy Markdown
Member

Noticed this here: https://github.com/getsentry/sentry-javascript/pull/22869/changes

The flag for checking native flag is both incorrect I believe and also misleading. Some problems with it:

  1. The logic is wrong - skipNativeFetchCheck && !supportsNativeFetch() would only check if we define that the check should be skipped?
  2. It fundamentally can only be checked (and is only relevant) in browser, because we build an iframe etc.
  3. It is also not ideal to do this at addFetchInstrumentationHandler level, as this can be called multiple times but instrumentFetch is only called once (whichever is the first caller) so that is also non ideal.

Now, instead we simply guard this on isBrowser() which imho makes more sense and is clearer.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b9bc3ac. Configure here.

// falls back to an iframe DOM check to detect a polyfilled/wrapped `fetch` (which we don't want to
// double-instrument alongside XHR). Outside the browser there is no DOM, and `fetch` may be
// legitimately wrapped by the host (e.g. Next.js on Bun), so we always patch the global there.
if (isBrowser() && !supportsNativeFetch()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Feat PR lacks required tests

Medium Severity

This is a feat PR, but the diff has no integration or E2E test covering the new isBrowser()-gated native-fetch check in instrumentFetch. That violates the testing convention that feat PRs include at least one integration or E2E test. Without that, browser skip vs non-browser always-patch behavior can regress unnoticed.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit b9bc3ac. Configure here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this is tested in various places already.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Arguably this is a ref(core), I guess, since it's really not adding any user-facing feature, I guess?

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.91 kB -0.01% -2 B 🔽
@sentry/browser - with treeshaking flags 28.11 kB - -
@sentry/browser (incl. Tracing) 47.37 kB -0.02% -8 B 🔽
@sentry/browser (incl. Tracing + Span Streaming) 47.37 kB -0.02% -8 B 🔽
@sentry/browser (incl. Tracing, Profiling) 52.14 kB -0.02% -7 B 🔽
@sentry/browser (incl. Tracing, Replay) 86.71 kB -0.01% -5 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 76.14 kB -0.01% -7 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 91.42 kB -0.01% -5 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 104.06 kB -0.01% -8 B 🔽
@sentry/browser (incl. Feedback) 47.21 kB -0.01% -4 B 🔽
@sentry/browser (incl. sendFeedback) 34.75 kB -0.02% -4 B 🔽
@sentry/browser (incl. FeedbackAsync) 39.86 kB -0.01% -3 B 🔽
@sentry/browser (incl. Metrics) 30.99 kB -0.01% -2 B 🔽
@sentry/browser (incl. Logs) 31.22 kB -0.01% -3 B 🔽
@sentry/browser (incl. Metrics & Logs) 31.89 kB -0.01% -3 B 🔽
@sentry/react 31.73 kB -0.01% -3 B 🔽
@sentry/react (incl. Tracing) 49.63 kB -0.02% -6 B 🔽
@sentry/vue 34.98 kB -0.02% -4 B 🔽
@sentry/vue (incl. Tracing) 49.35 kB -0.02% -9 B 🔽
@sentry/svelte 29.93 kB -0.01% -2 B 🔽
CDN Bundle 31.97 kB -0.05% -13 B 🔽
CDN Bundle (incl. Tracing) 47.73 kB -0.02% -8 B 🔽
CDN Bundle (incl. Logs, Metrics) 33.53 kB -0.04% -12 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) 49.08 kB -0.02% -9 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) 72.89 kB -0.02% -11 B 🔽
CDN Bundle (incl. Tracing, Replay) 85.35 kB -0.02% -9 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.66 kB -0.01% -8 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 91.15 kB -0.01% -5 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.45 kB -0.02% -13 B 🔽
CDN Bundle - uncompressed 95.47 kB -0.03% -20 B 🔽
CDN Bundle (incl. Tracing) - uncompressed 143.24 kB -0.01% -12 B 🔽
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.18 kB -0.02% -20 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 147.22 kB -0.01% -12 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 224.94 kB -0.01% -20 B 🔽
CDN Bundle (incl. Tracing, Replay) - uncompressed 262.5 kB -0.01% -12 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 266.46 kB -0.01% -12 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 276.2 kB -0.01% -12 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 280.16 kB -0.01% -12 B 🔽
@sentry/nextjs (client) 52.21 kB -0.01% -3 B 🔽
@sentry/sveltekit (client) 47.81 kB -0.02% -6 B 🔽
@sentry/core/server 79.98 kB -0.02% -13 B 🔽
@sentry/core/browser 51.91 kB -0.04% -16 B 🔽
@sentry/node 121.61 kB - -
@sentry/node/import (ESM hook with diagnostics-channel injection) 0 B added added
@sentry/node - without tracing 85.15 kB - -
@sentry/aws-serverless 93.41 kB - -
@sentry/cloudflare (withSentry) - minified 199.11 kB -0.01% -15 B 🔽
@sentry/cloudflare (withSentry) 490.31 kB -0.02% -95 B 🔽

View base workflow run

@mydea
mydea marked this pull request as ready for review July 31, 2026 07:58
@mydea
mydea requested review from a team as code owners July 31, 2026 07:58
@mydea
mydea requested review from JPeer264, Lms24, isaacs, logaretm and msonnb and removed request for a team July 31, 2026 07:58

@isaacs isaacs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Significant win!

// falls back to an iframe DOM check to detect a polyfilled/wrapped `fetch` (which we don't want to
// double-instrument alongside XHR). Outside the browser there is no DOM, and `fetch` may be
// legitimately wrapped by the host (e.g. Next.js on Bun), so we always patch the global there.
if (isBrowser() && !supportsNativeFetch()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Arguably this is a ref(core), I guess, since it's really not adding any user-facing feature, I guess?

@isaacs
isaacs force-pushed the fn/native-fetch-check branch from b9bc3ac to ae94c1a Compare July 31, 2026 17:02
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.

4 participants