⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@nicohrubec
Copy link
Member

@nicohrubec nicohrubec commented Jan 7, 2026

Adds wrapConfigWithSentry vite config wrapper to enable automatic source map uploads in Tanstack Start applications.

What it does
I tried to align with what we do in other SDKs (e.g. solid start). On a high-level it:

  • Uploads source maps to Sentry using @sentry/vite-plugin if configured, mainly passing through the options set by the user
  • If the source maps option is not defined and also the files to delete option is not defined we enable cleaning up all .map files after the source map upload
  • If the source map configuration is undefined we additionally enable hidden source map upload

Usage

  // vite.config.ts
  import { defineConfig } from 'vite';
  import { wrapConfigWithSentry } from '@sentry/tanstackstart-react';

  export default defineConfig(
    wrapConfigWithSentry(
      {
        plugins: [/* your plugins */],
      },
      {
        org: 'my-org',
        project: 'my-project',
        // authToken via SENTRY_AUTH_TOKEN env var
      },
    ),
  );

Tests

  • Added unit tests for sourceMaps.ts and addSentryPlugins.ts covering plugin composition, options passing, and source map settings logic
  • Updated the E2E test to use the wrapper (although no explicit checks are done there)

Closes #18664

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,888 - 9,339 -5%
GET With Sentry 1,671 19% 1,762 -5%
GET With Sentry (error only) 5,992 67% 6,107 -2%
POST Baseline 1,196 - 1,202 -0%
POST With Sentry 585 49% 594 -2%
POST With Sentry (error only) 1,055 88% 1,069 -1%
MYSQL Baseline 3,350 - 3,335 +0%
MYSQL With Sentry 466 14% 456 +2%
MYSQL With Sentry (error only) 2,717 81% 2,703 +1%

View base workflow run

@nicohrubec nicohrubec changed the title feat(tanstackstart-react): Add vite config wrapper feat(tanstackstart-react): Add Vite Config Wrapper for Source Map Uploads Jan 8, 2026
@nicohrubec nicohrubec marked this pull request as ready for review January 8, 2026 08:37
/**
* Build options for the Sentry plugin. These options are used during build-time by the Sentry SDK.
*/
export type SentryTanstackStartReactPluginOptions = {
Copy link
Member

Choose a reason for hiding this comment

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

You can/should extend from this type, so we can make sure that all build-time options are aligned:

Copy link
Member Author

Choose a reason for hiding this comment

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

ah nice thanks I did not know that existed, updated

if (process.env.NODE_ENV !== 'development') {
// Check if source maps upload is enabled
// Default to enabled
const sourceMapsEnabled = options.sourceMapsUploadOptions?.enabled ?? true;
Copy link
Member

Choose a reason for hiding this comment

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

You probably want to use options.sourcemaps.disable here. Also make sure people can still create a release, even if they don't want to upload source maps.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated to use disable

@s1gr1d
Copy link
Member

s1gr1d commented Jan 12, 2026

A general thought I had on this: Are the sources included in Nitro source maps? In the Nuxt SDK, we have to disable this setting:

nitroConfig.rollupConfig.output.sourcemapExcludeSources = false;

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Naive question for now: What's the advantage over this wrapper that we can't achieve with just exporting a plugin? If we need to modify the vite config, Vite offers plugin hooks to do so from within a plugin.

I'd personally prefer the plugin approach because this is a pattern that users are more used to than wrapping their config. If you or anyone else has different opinions, let's hear it :D

Comment on lines +38 to +40
sourcemaps: {
filesToDeleteAfterUpload: sourcemaps?.filesToDeleteAfterUpload ?? updatedFilesToDeleteAfterUpload,
},
Copy link

Choose a reason for hiding this comment

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

Bug: The makeAddSentryVitePlugin function only passes filesToDeleteAfterUpload from the sourcemaps config, silently ignoring other important options like assets and ignore.
Severity: HIGH

🔍 Detailed Analysis

The makeAddSentryVitePlugin function incorrectly constructs the options for the Sentry Vite plugin by only passing the filesToDeleteAfterUpload property from the user's sourcemaps configuration. Other valid properties from the SourceMapsOptions interface, such as assets and ignore, are silently dropped. This means if a user configures sourcemaps.assets to specify which files to upload or sourcemaps.ignore to exclude certain files, these settings will have no effect. This can lead to incorrect or incomplete source map uploads in production, hindering debugging efforts.

💡 Suggested Fix

Spread the user's sourcemaps configuration object into the options passed to sentryVitePlugin() to ensure all properties are preserved, then selectively override properties as needed. For example: sourcemaps: { ...sourcemaps, filesToDeleteAfterUpload: sourcemaps?.filesToDeleteAfterUpload ?? updatedFilesToDeleteAfterUpload }.

🤖 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/sourceMaps.ts#L38-L40

Potential issue: The `makeAddSentryVitePlugin` function incorrectly constructs the
options for the Sentry Vite plugin by only passing the `filesToDeleteAfterUpload`
property from the user's `sourcemaps` configuration. Other valid properties from the
`SourceMapsOptions` interface, such as `assets` and `ignore`, are silently dropped. This
means if a user configures `sourcemaps.assets` to specify which files to upload or
`sourcemaps.ignore` to exclude certain files, these settings will have no effect. This
can lead to incorrect or incomplete source map uploads in production, hindering
debugging efforts.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 8549612

},
},
}),
];
Copy link

Choose a reason for hiding this comment

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

Missing release option forwarding to vite plugin

Medium Severity

The makeAddSentryVitePlugin function accepts BuildTimeOptionsBase which includes a release property for configuring Sentry release options. However, the function only destructures and forwards a subset of options (authToken, bundleSizeOptimizations, debug, org, project, sourcemaps, telemetry) to sentryVitePlugin, completely ignoring the release option. This means users who configure release options like release.name will have their configuration silently ignored. Other SDKs like Nuxt and Astro properly forward the release option. Additionally, sentryUrl, headers, silent, and errorHandler are also not forwarded, though release is most critical as noted in the PR discussion.

Fix in Cursor Fix in Web

// Only add source map plugins in production builds
if (process.env.NODE_ENV !== 'development') {
// Check if source maps upload is enabled, default is enabled
const sourceMapsDisabled = options.sourcemaps?.disable === true || options.sourcemaps?.disable === 'disable-upload';
Copy link

Choose a reason for hiding this comment

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

disable-upload option skips debug ID injection incorrectly

Medium Severity

The sourceMapsDisabled check treats 'disable-upload' identically to true, skipping all plugins entirely. However, according to the BuildTimeOptionsBase type documentation, 'disable-upload' should still "inject debug IDs into the build artifacts" while only disabling the upload. The current implementation prevents debug ID injection when users set sourcemaps.disable to 'disable-upload', breaking the documented functionality for users who want to manually upload source maps later.

Fix in Cursor Fix in Web

* A Sentry plugin for adding the @sentry/vite-plugin to automatically upload source maps to Sentry.
*/
export function makeAddSentryVitePlugin(options: BuildTimeOptionsBase, viteConfig: UserConfig): Plugin[] {
const { authToken, bundleSizeOptimizations, debug, org, project, sourcemaps, telemetry } = options;
Copy link

Choose a reason for hiding this comment

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

Missing sentryUrl option blocks self-hosted users

Medium Severity

The sentryUrl option from BuildTimeOptionsBase is not extracted or forwarded to sentryVitePlugin. This option is documented as "The base URL of your Sentry instance. Use this if you are using a self-hosted or Sentry instance other than sentry.io." Without forwarding this option (as url to the vite plugin), self-hosted Sentry users cannot use this wrapper to upload source maps to their own Sentry instance. Other SDK implementations like Astro correctly forward this option.

Fix in Cursor Fix in Web

project: project ?? process.env.SENTRY_PROJECT,
sourcemaps: {
filesToDeleteAfterUpload: sourcemaps?.filesToDeleteAfterUpload ?? updatedFilesToDeleteAfterUpload,
},
Copy link

Choose a reason for hiding this comment

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

Incomplete sourcemaps options forwarding to plugin

Medium Severity

The sourcemaps object passed to sentryVitePlugin only includes filesToDeleteAfterUpload, but the BuildTimeOptionsBase.sourcemaps interface also defines assets and ignore options. Users expecting to configure which source map files to upload via sourcemaps.assets or exclude via sourcemaps.ignore will find these options are silently ignored. Other SDKs like nuxt forward these options properly.

Fix in Cursor Fix in Web

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.

Automatically enable source maps upload from vite config wrapper

4 participants