Skip to content

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

Draft
timfish wants to merge 1 commit into
ref/sveltekit-call-site-rewriterfrom
ref/tanstackstart-call-site-rewriter
Draft

timfish wants to merge 1 commit 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: 7774bea (PR test merge using develop at b6a61d7)

Against: f2ee787 (develop) · base run #65001

⚠️ Baseline mismatch: 8 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 b6a61d7 finishes.

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.72 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.72 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.69 kB - -
@sentry/browser (incl. Tracing, Replay) 93.02 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.61 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 97.76 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 110.75 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.09 kB - -
@sentry/vue 38.67 kB - -
@sentry/vue (incl. Tracing) 55.73 kB - -
@sentry/svelte 30.43 kB - -
@sentry/remix (Remix 3 client bundle) 57.8 kB - -
CDN Bundle 32.19 kB - -
CDN Bundle (incl. Tracing) 53.24 kB - -
CDN Bundle (incl. Logs, Metrics) 34.47 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.19 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 75.88 kB - -
CDN Bundle (incl. Tracing, Replay) 91.46 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.39 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 97.56 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.56 kB - -
CDN Bundle - uncompressed 94.67 kB - -
CDN Bundle (incl. Tracing) - uncompressed 157.63 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.14 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.37 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.71 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 279.32 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 285.05 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 293.03 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 298.74 kB - -
@sentry/nextjs (client) 58.04 kB - -
@sentry/sveltekit (client) 53.23 kB - -
@sentry/core/server 44.25 kB - -
@sentry/core/browser 13.93 kB - -
@sentry/node 155.71 kB +0.02% +20 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.26 kB - -
@sentry/node - without tracing 96.9 kB +0.02% +19 B 🔺
@sentry/node - without channel injection 136.04 kB +0.02% +22 B 🔺
@sentry/aws-serverless 105.11 kB +0.02% +20 B 🔺
@sentry/cloudflare (withSentry) - minified 200.67 kB - -
@sentry/cloudflare (withSentry) 499.05 kB - -
@sentry/nextjs/cloudflare (withSentry) - minified 221.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. 3 successful. See the run.

Successful checks
Check Status
✅ 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 43s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 37s Details

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 51b3096 to a13330c Compare November 4, 2026 14:23

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.

1 participant