Skip to content

ref(tanstackstart-react): Wrap middleware arrays with the rewriter core - #26104

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

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

Conversation

@timfish

@timfish timfish commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Why: The regex rewrite broke on nested arrays and on a ] inside a string. It skipped the whole file once wrapMiddlewaresWithSentry appeared anywhere in it, it found start files by start in the file path, and the rewritten files had no source maps. The plugin now finds middleware arrays in the AST, skips each wrapped site on its own, and returns a source map. A start file is now any file that calls createStart(), and the plugin only wraps requestMiddleware and functionMiddleware inside that call. The warning text is unchanged.

How to review: src/vite/autoInstrumentMiddleware.ts, then the new test cases.

Unsure about: A middleware array followed by as const is not wrapped, and the plugin gives no warning for it.

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: c958b2c (PR test merge using develop at a3249b6)

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

⚠️ Baseline mismatch: 10 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 a3249b6 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 -0.01% -1 B 🔽
@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.37 kB - -
@sentry/aws-serverless 100.44 kB +0.01% +2 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

All optional checks were successful. 6 successful. See the run.

Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps (delete all) 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 tanstackstart-react-cloudflare 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 tanstackstart-react-sourcemaps (manual upload) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps (no upload) Test (optional) Successful in 1m Details

@timfish
timfish force-pushed the ref/tanstackstart-call-site-rewriter branch from 51b3096 to a13330c Compare November 4, 2026 14:23
@timfish
timfish force-pushed the ref/tanstackstart-call-site-rewriter branch from a13330c to 8ff429f Compare November 23, 2026 15:27
@timfish
timfish force-pushed the ref/tanstackstart-call-site-rewriter branch from 8ff429f to e410d72 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.

Stale Bugbot comment from a previous run.

@timfish
timfish force-pushed the ref/tanstackstart-call-site-rewriter branch 2 times, most recently from 6d82c1a to 5750fcb Compare November 25, 2026 21:55
@timfish
timfish force-pushed the ref/tanstackstart-call-site-rewriter branch from 5750fcb to c609009 Compare November 26, 2026 10:40
@timfish
timfish force-pushed the ref/tanstackstart-call-site-rewriter branch from c609009 to 08f8117 Compare November 26, 2026 10:46

@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, just one thing before merging this

include: { id: SOURCE_FILE_REGEX, contains },
apply: ctx => {
wrapSites(ctx, findSites, debug);
if (ctx.state.needsImport && !hasImport(ctx.ast, SENTRY_MODULE, WRAPPER)) {

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.

There could be an issue with double-imports. Can you check that?

When a route file imports wrapMiddlewaresWithSentry from a re-export (e.g. ~/lib/sentry) and has an unwrapped site, we add a second import of the same name, and the build fails with "Identifier 'wrapMiddlewaresWithSentry' has already been declared". Could we check collectDeclaringStatements(ctx.ast).has(WRAPPER) instead of hasImport, and add a test with a re-exported import?

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.

Good catch, fixed in 8cef040 with a re-export test, and the same for SvelteKit in 920013b.

@timfish
timfish force-pushed the ref/tanstackstart-call-site-rewriter branch from 08f8117 to 8cef040 Compare November 26, 2026 12:45

@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 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 8cef040. Configure here.

@timfish
timfish force-pushed the ref/tanstackstart-call-site-rewriter branch from 8cef040 to 69d041e Compare November 26, 2026 12:59
@timfish
timfish force-pushed the ref/tanstackstart-call-site-rewriter branch from 69d041e to c8ab5e8 Compare November 26, 2026 13:34
@timfish
timfish force-pushed the ref/tanstackstart-call-site-rewriter branch from c8ab5e8 to f111856 Compare November 26, 2026 14:07
@timfish
timfish force-pushed the ref/tanstackstart-call-site-rewriter branch from f111856 to be3b775 Compare November 26, 2026 14:40
The regex rewrite broke on nested arrays and on a `]` inside a string. It skipped a whole file once `wrapMiddlewaresWithSentry` appeared anywhere in it, and it found start files by `start` in the file path. Wrapped files also lost their source maps.

The plugin now finds middleware arrays in the AST, skips each wrapped site on its own, and returns a source map. A start file is any file that calls `createStart()`.
@timfish
timfish force-pushed the ref/tanstackstart-call-site-rewriter branch from be3b775 to 8bdae62 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