-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(tanstackstart-react): Add Vite Config Wrapper for Source Map Uploads #18712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
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.
|
| /** | ||
| * Build options for the Sentry plugin. These options are used during build-time by the Sentry SDK. | ||
| */ | ||
| export type SentryTanstackStartReactPluginOptions = { |
There was a problem hiding this comment.
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:
| export interface BuildTimeOptionsBase { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to use disable
|
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:
|
Lms24
left a comment
There was a problem hiding this 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
| sourcemaps: { | ||
| filesToDeleteAfterUpload: sourcemaps?.filesToDeleteAfterUpload ?? updatedFilesToDeleteAfterUpload, | ||
| }, |
There was a problem hiding this comment.
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
| }, | ||
| }, | ||
| }), | ||
| ]; |
There was a problem hiding this comment.
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.
| // 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'; |
There was a problem hiding this comment.
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.
| * 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; |
There was a problem hiding this comment.
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.
| project: project ?? process.env.SENTRY_PROJECT, | ||
| sourcemaps: { | ||
| filesToDeleteAfterUpload: sourcemaps?.filesToDeleteAfterUpload ?? updatedFilesToDeleteAfterUpload, | ||
| }, |
There was a problem hiding this comment.
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.
Adds
wrapConfigWithSentryvite 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:
@sentry/vite-pluginif configured, mainly passing through the options set by the user.mapfiles after the source map uploadhiddensource map uploadUsage
Tests
sourceMaps.tsandaddSentryPlugins.tscovering plugin composition, options passing, and source map settings logicCloses #18664