Skip to content

fix(sveltekit): Read navigation untracked in the Kit 3 fetch wrapper - #26136

Merged
chargome merged 1 commit into
developfrom
js-4071-fetch-effect
Nov 5, 2026
Merged

chargome merged 1 commit into
developfrom
js-4071-fetch-effect

Conversation

@chargome

@chargome chargome commented Nov 5, 2026

Copy link
Copy Markdown
Member

Why: On SvelteKit 3 the fetch wrapper reads navigating from $app/state before every request. When a $effect calls fetch synchronously, that read made navigating a dependency of the effect, so it re-ran (and re-sent its requests) on every navigation. The read now goes through untrack. svelte is marked external in rollup so the import resolves to the app's Svelte 5, and a small build-time .d.ts declares untrack because the package is type-checked against Svelte 4.

How to review: The fix is one line in navigationState.svelte.ts. The new e2e test in sveltekit-3 fails without it (4 requests instead of 1).

Closes #26129

The SvelteKit 3 fetch wrapper read `navigating` from `$app/state` tracked. A `$effect` that
calls fetch synchronously then picked up `navigating` as a dependency and re-ran (re-sending
its requests) on every navigation. Read it with `untrack` instead.

Fixes #26129
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chargome chargome self-assigned this Nov 5, 2026
@chargome

chargome commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

bugbot run

@linear-code

linear-code Bot commented Nov 5, 2026

Copy link
Copy Markdown

JS-4071

@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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit fd1e36e. Configure here.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 3b9c070 (PR test merge using develop at c054e7a)

Against: c054e7a (develop) · base run #65086

✅ Baseline matches: this diff contains only this PR's changes.

Path Size % Change Change
@sentry/browser 30.4 kB - -
@sentry/browser - with treeshaking flags 28.54 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.43 kB - -
@sentry/browser (incl. Tracing) 52.73 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.73 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.7 kB - -
@sentry/browser (incl. Tracing, Replay) 93.03 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.63 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 97.78 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 110.77 kB - -
@sentry/browser (incl. Feedback) 47.98 kB - -
@sentry/browser (incl. sendFeedback) 35.5 kB - -
@sentry/browser (incl. FeedbackAsync) 40.61 kB - -
@sentry/browser (incl. Metrics) 31.44 kB - -
@sentry/browser (incl. Logs) 31.73 kB - -
@sentry/browser (incl. Metrics & Logs) 32.45 kB - -
@sentry/react 32.29 kB - -
@sentry/react (incl. Tracing) 55.1 kB - -
@sentry/vue 38.67 kB - -
@sentry/vue (incl. Tracing) 55.75 kB - -
@sentry/svelte 30.43 kB - -
@sentry/remix (Remix 3 client bundle) 57.82 kB - -
CDN Bundle 32.2 kB - -
CDN Bundle (incl. Tracing) 53.26 kB - -
CDN Bundle (incl. Logs, Metrics) 34.47 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.2 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 75.88 kB - -
CDN Bundle (incl. Tracing, Replay) 91.47 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.4 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 97.58 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.58 kB - -
CDN Bundle - uncompressed 94.67 kB - -
CDN Bundle (incl. Tracing) - uncompressed 157.67 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.14 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.41 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.71 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 279.36 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 285.08 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 293.06 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 298.77 kB - -
@sentry/nextjs (client) 58.05 kB - -
@sentry/sveltekit (client) 53.24 kB - -
@sentry/core/server 44.25 kB - -
@sentry/core/browser 13.93 kB - -
@sentry/node 156.06 kB +0.02% +19 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.28 kB - -
@sentry/node - without tracing 96.91 kB +0.02% +16 B 🔺
@sentry/node - without channel injection 136.38 kB +0.02% +18 B 🔺
@sentry/aws-serverless 105.12 kB +0.02% +20 B 🔺
@sentry/cloudflare (withSentry) - minified 200.67 kB - -
@sentry/cloudflare (withSentry) 499.05 kB - -
@sentry/nextjs/cloudflare (withSentry) - minified 222.67 kB - -

View base workflow run

@chargome
chargome marked this pull request as ready for review November 5, 2026 14:00
@chargome
chargome requested review from a team as code owners November 5, 2026 14:00
@chargome
chargome requested review from Lms24, andreiborza, isaacs, logaretm, nicohrubec and s1gr1d and removed request for a team, isaacs, logaretm and s1gr1d November 5, 2026 14:00
*/
export function getCurrentNavigation(): Navigation | null {
return _snapshot();
return untrack(_snapshot);

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.

Just to double-check: This file is only pulled in on Svelte 5, correct? Just to make sure we don't break someone on Svelte 4 where I think this function wasn't available.

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.

Yes, just used on svelte5BrowserTracing.ts

@chargome
chargome merged commit 89d33a9 into develop Nov 5, 2026
57 checks passed
@chargome
chargome deleted the js-4071-fetch-effect branch November 5, 2026 14:07
43081j pushed a commit to 43081j/sentry-javascript that referenced this pull request Nov 9, 2026
…etsentry#26136)

**Why:** On SvelteKit 3 the fetch wrapper reads `navigating` from
`$app/state` before every request. When a `$effect` calls `fetch`
synchronously, that read made `navigating` a dependency of the effect,
so it re-ran (and re-sent its requests) on every navigation. The read
now goes through `untrack`. `svelte` is marked external in rollup so the
import resolves to the app's Svelte 5, and a small build-time `.d.ts`
declares `untrack` because the package is type-checked against Svelte 4.

**How to review:** The fix is one line in `navigationState.svelte.ts`.
The new e2e test in `sveltekit-3` fails without it (4 requests instead
of 1).

Closes getsentry#26129

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

@sentry/sveltekit: fetch wrapper subscribes the calling $effect to navigating, re-running it on every navigation (SvelteKit 3)

2 participants