Skip to content

feat(tanstackstart-react): Compose Nitro server source maps to original TypeScript - #24356

Open
kyrylolvov wants to merge 1 commit into
getsentry:developfrom
kyrylolvov:feat/tanstackstart-nitro-server-sourcemaps
Open

kyrylolvov wants to merge 1 commit into
getsentry:developfrom
kyrylolvov:feat/tanstackstart-nitro-server-sourcemaps

Conversation

@kyrylolvov

@kyrylolvov kyrylolvov commented Sep 13, 2026

Copy link
Copy Markdown

Server-function errors in TanStack Start stayed minified even when source maps were uploaded. Frontend maps already unminified. The server bundle is a second Nitro pass, and its maps never pointed at the original TypeScript.

Fixes #21012

Root cause
TanStack Start compiles server code twice: Vite SSR intermediates under node_modules/.nitro/, then Nitro's final Rollup into .output/server. Sentry uploaded the final maps.

Nitro's sourcemapMinify clears mappings for any chunk whose path contains node_modules. The intermediates live there, so those maps were often empty. Separately, Rollup loaded the intermediates as plain JS and ignored the adjacent .map, so even intact maps pointed at generated files. Setting vite.build.sourcemap does not set nitro.sourcemap. Uploading both folders with sentry-cli does not compose them.

Solution
sentryTanstackStart() now configures Nitro the same way SolidStart's Vite plugin does (enforce: 'pre', hidden maps if unset, sourcemapMinify: false) and adds a Rollup load hook that returns { code, map } for the SSR intermediates so the final maps compose through to TypeScript. Source paths like ../../../src/...?tss-serverfn-split are rewritten to ./src/... on upload.

@sentry/nitro is not a dependency: that module also enables tracing-channel instrumentation and a second upload, which would double-instrument TanStack Start.

Before
sentry-before

After
sentry-after

@kyrylolvov
kyrylolvov marked this pull request as ready for review September 13, 2026 16:46
@kyrylolvov
kyrylolvov requested a review from a team as a code owner September 13, 2026 16:46
@kyrylolvov
kyrylolvov requested review from mydea and s1gr1d and removed request for a team September 13, 2026 16:46

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

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 77b0edd. Configure here.

}

return id.includes('/.nitro/vite/services/ssr/') || id.includes('.nitro\\vite\\services\\ssr\\');
}

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 lacks integration or E2E test

Medium Severity

This feat only adds unit tests for Nitro source-map composition. An integration or E2E test is needed to confirm server-function errors unminify to the original TypeScript in a real TanStack Start plus Nitro build. I flagged this because the review guidelines require at least one integration or E2E test on feat PRs.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 77b0edd. Configure here.

plugins.push(makeNitroSourceMapsPlugin(options));
}

plugins.push(...makeAddSentryVitePlugin(options));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The source map deletion plugin runs before the source map enabling plugin. This causes intermediate SSR source maps to be deleted prematurely, breaking server-side source map composition in the default configuration.
Severity: HIGH

Suggested Fix

Reorder the plugin registration in sentryTanstackStart.ts. The makeEnableSourceMapsVitePlugin call should be placed before the makeAddSentryVitePlugin call. This ensures the config.build.sourcemap property is set before the deletion plugin's logic runs, preventing it from incorrectly scheduling the deletion of all map files.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/tanstackstart-react/src/vite/sentryTanstackStart.ts#L110

Potential issue: In the default configuration, the Vite plugin responsible for deleting
source maps after upload (`sentry-tanstackstart-files-to-delete-after-upload-plugin`) is
scheduled before the plugin that enables them
(`sentry-tanstackstart-react-source-maps`). Because the deletion plugin checks if
`build.sourcemap` is defined before the enabling plugin has a chance to set it, it
defaults to scheduling the deletion of all map files (`./**/*.map`). This broad pattern
incorrectly deletes intermediate SSR source maps required by Nitro's second build pass.
As a result, server-side stack traces are not correctly unminified in Sentry. This issue
does not occur if a user manually configures `build.sourcemap` or
`filesToDeleteAfterUpload`.

Did we get this right? 👍 / 👎 to inform future reviews.

@kyrylolvov
kyrylolvov force-pushed the feat/tanstackstart-nitro-server-sourcemaps branch from ec73d27 to 77b0edd Compare September 13, 2026 18:19
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.

tanstack-start: source maps support for server code

1 participant