Skip to content

ref(sveltekit): Wrap load functions in place with the rewriter core - #26103

Open
timfish wants to merge 5 commits into
ref/cloudflare-call-site-rewriterfrom
ref/sveltekit-call-site-rewriter
Open

timfish wants to merge 5 commits into
ref/cloudflare-call-site-rewriterfrom
ref/sveltekit-call-site-rewriter

Conversation

@timfish

@timfish timfish commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Why: The load hook served a proxy module that re-exported each route file under a ?sentry-auto-wrap query. That doubled the module count per route, put the query into stack frames and source maps (which needed extra code in rewriteFramesIntegration and the source map clean-up to remove it), and could not wrap export { load } from './shared'. The transform now wraps the load export in the route file itself and skips loads the user wrapped by hand. It reads the code Vite passes in instead of reading the file from disk a second time, so acorn and @sveltejs/acorn-typescript are no longer dependencies.

How to review: Start with src/vite/autoInstrument.ts. The other source changes remove the query handling.

Unsure about: At build time, a load that ends in satisfies PageLoad doesn't count as already wrapped. The runtime guard still stops a double wrap.

Ref #25776

@timfish
timfish added this pull request to stack #26105 November 4, 2026 13:58
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: e343682 (PR test merge using develop at f58aeb8)

Against: 71f41ed (develop) · base run #68183

⚠️ Baseline mismatch: 4 develop commit(s) in the PR build are missing from the baseline. Their size changes also affect this comparison. Compare commits. Re-run once develop's baseline build for f58aeb8 finishes.

Path Size % Change Change
@sentry/browser 30.55 kB - -
@sentry/browser - with treeshaking flags 28.74 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.61 kB - -
@sentry/browser (incl. Tracing) 53.68 kB - -
@sentry/browser (incl. Tracing Core) 40.6 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 53.68 kB - -
@sentry/browser (incl. Tracing, Profiling) 56.57 kB - -
@sentry/browser (incl. Tracing, Replay) 93.6 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 82.4 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 98.46 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 111.41 kB - -
@sentry/browser (incl. Feedback) 48.41 kB - -
@sentry/browser (incl. sendFeedback) 31.12 kB - -
@sentry/browser (incl. FeedbackAsync) 36.18 kB - -
@sentry/browser (incl. Metrics) 31.87 kB - -
@sentry/browser (incl. Logs) 32.15 kB - -
@sentry/browser (incl. Metrics & Logs) 32.81 kB - -
@sentry/react 32.58 kB - -
@sentry/react (incl. Tracing) 56.42 kB - -
@sentry/vue 38.76 kB - -
@sentry/vue (incl. Tracing) 56.69 kB - -
@sentry/svelte 30.58 kB - -
@sentry/effect (client) 42.23 kB - -
@sentry/effect (client, incl. Tracing) 54.97 kB - -
@sentry/effect (client, incl. Tracing, Logs, Metrics) 66.32 kB - -
@sentry/remix (Remix 3 client bundle) 59.41 kB - -
CDN Bundle 32.39 kB - -
CDN Bundle (incl. Tracing) 54.05 kB - -
CDN Bundle (incl. Logs, Metrics) 35.14 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 56.52 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 76.1 kB - -
CDN Bundle (incl. Tracing, Replay) 91.85 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 94.38 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 97.33 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.8 kB - -
CDN Bundle - uncompressed 94.58 kB - -
CDN Bundle (incl. Tracing) - uncompressed 159.87 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 102.92 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 167.49 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 233.32 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 280.3 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 287.93 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 292.24 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 299.85 kB - -
@sentry/nextjs (client) 60.09 kB - -
@sentry/sveltekit (client) 55.03 kB - -
@sentry/core/server 45.84 kB - -
@sentry/core/browser 14.48 kB - -
@sentry/node 157.4 kB - -
@sentry/node/import (ESM hook with diagnostics-channel injection) 83.45 kB - -
@sentry/node - without tracing 89.81 kB +0.01% +1 B 🔺
@sentry/node - without channel injection 146.38 kB +0.01% +2 B 🔺
@sentry/aws-serverless 100.44 kB +0.01% +1 B 🔺
@sentry/cloudflare (withSentry) - minified 211.97 kB - -
@sentry/cloudflare (withSentry) 491.78 kB - -
@sentry/cloudflare (withSentry, instrumented CommonJS package) - minified 214.92 kB - -
@sentry/nextjs/cloudflare (withSentry) - minified 237.22 kB - -

View base workflow run

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 7 not successful, 58 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E nuxt-5 (cloudflare) Test (optional) Failing after 1m Details
❌ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Failing after 1m Details
❌ CI: Optional E2E Tests / E2E nuxt-5 (deno) Test (optional) Failing after 1m Details
❌ CI: Optional E2E Tests / E2E nuxt-5 (kv-cache) Test (optional) Failing after 1m Details
❌ CI: Optional E2E Tests / E2E nuxt-5 (development) Test (optional) Failing after 2m Details
❌ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Failing after 1m Details
❌ CI: Optional E2E Tests / E2E nuxt-5 (bun) Test (optional) Failing after 1m Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E hono-5 (deno) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E hapi-21 (deno) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-4-sourcemaps (Vite server) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry (static trace lifecycle) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-tunnel (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E hapi-21 (bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E hono-5 (bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E hono-5 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-14-supabase Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E react-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E vinext-cf-workers (workers cache) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-tunnel Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 (MCP SDK OpenTelemetry) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps enabled by Sentry) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (no upload) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 (manual upload) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-without-tracing-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 (delete all) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E hono-5 (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps (delete all) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E astro-7 (static trace lifecycle) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E solidstart-2-tunnel Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps (no upload) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps (manual upload) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 (no upload) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve (content off) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve (0.x) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E vue-3 (no Options API) Test (optional) Successful in 1m Details

@timfish
timfish force-pushed the ref/sveltekit-call-site-rewriter branch from 48f0c25 to 9aafb1f Compare November 4, 2026 14:23
@timfish
timfish force-pushed the ref/sveltekit-call-site-rewriter branch 2 times, most recently from 1f3c7db to f8bc1f2 Compare November 25, 2026 20:31
@timfish
timfish marked this pull request as ready for review November 25, 2026 20:44

@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 using default effort and found 2 potential issues.

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 f8bc1f2. Configure here.

@timfish
timfish requested a review from Lms24 November 25, 2026 20:49
@timfish
timfish force-pushed the ref/sveltekit-call-site-rewriter branch from f8bc1f2 to a2f6943 Compare November 25, 2026 20:54
@timfish
timfish force-pushed the ref/sveltekit-call-site-rewriter branch from a2f6943 to 1e88c9f Compare November 25, 2026 21:55
@timfish
timfish force-pushed the ref/sveltekit-call-site-rewriter branch from 1e88c9f to d68a3ce Compare November 26, 2026 10:40
@timfish
timfish force-pushed the ref/sveltekit-call-site-rewriter branch 2 times, most recently from 96e3d2a to 920013b Compare November 26, 2026 12:45
@timfish
timfish force-pushed the ref/sveltekit-call-site-rewriter branch 2 times, most recently from 214cfd6 to a5777fc Compare November 26, 2026 13:34
@timfish
timfish force-pushed the ref/sveltekit-call-site-rewriter branch from a5777fc to 444634d Compare November 26, 2026 14:07
@timfish
timfish force-pushed the ref/sveltekit-call-site-rewriter branch from 444634d to 56f21a1 Compare November 26, 2026 14:40
Comment on lines +68 to +71
? [loadRule(/^\+(page|layout)\.(js|ts|mjs|mts)$/, 'wrapLoadWithSentry', debug)]
: [];
const serverRules = wrapServerLoadEnabled
? [loadRule(/^\+(page|layout)\.server\.(js|ts|mjs|mts)$/, 'wrapServerLoadWithSentry', debug)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Route loads with Vite’s ?v= query are not auto-wrapped

When Vite passes a route module id such as +page.ts?v=123, the basename rules do not match, so the route’s load function is left unwrapped and its Sentry load span is missed. Preserve the intentional exclusion of special imports such as ?raw when handling query-bearing ids.

Evidence
  • Auto-instrumentation is enabled by default, and transform passes the id directly to the rewriter without normalizing its query.
  • The rules use end-anchored basename patterns; the rewriter tests them against basename(id), so +page.ts?v=123 does not match +page.ts.
  • makeEntryFileMatcher documents that Vite appends queries like ?v=123 to module ids and strips the query; its test confirms a query-bearing SvelteKit entry id is accepted.
  • The auto-instrumentation test only checks that +page.ts?raw is excluded; it does not cover a version-query route id.

Identified by Warden · code-review · AC2-U3Q

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fix attempt detected (commit 479d9d1)

The auto-instrumentation logic was directly rewritten, but the rewriter still tests end-anchored basename rules against basename(id) without stripping query strings, so +page.ts?v=123 remains unwrapped.

The original issue appears unresolved. Please review and try again.

Evaluated by Warden

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The load hook on develop tests the same end-anchored regex against basename(id), so query ids were not wrapped before either; we can add that in a follow-up.

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

All good, but just one comment on the bugbot notice.

The `load` hook served a proxy module that re-exported the route file under a `?sentry-auto-wrap` query. That doubled the module count per route, leaked the query into stack frames and source maps, and could not wrap `export { load } from './shared'`.

The transform now wraps the `load` export in the route file itself, so the query and the code that stripped it again are gone. It reads the code Vite hands over instead of a second copy from disk, so acorn is no longer needed.
The proxy module renamed the route `load` to `load$1` in the bundle. In-place wrapping keeps the name.
… app

Load functions are wrapped in the route file itself, so no module carries the `?sentry-auto-wrap` query.
@timfish
timfish force-pushed the ref/sveltekit-call-site-rewriter branch from 56f21a1 to 479d9d1 Compare November 26, 2026 14:59

This branch has not been deployed

No deployments
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