Skip to content

Commit 7f9cd08

Browse files
chargomeclaude
andcommitted
fix(remix): Keep the bundler plugin when source maps are disabled
`sourcemaps.disable: true` skipped the whole bundler plugin, which also applies bundle size optimizations, module metadata, the application key and release management. The plugin already declines the upload on its own, so only the source map setting plugin needs gating. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 3b33542 commit 7f9cd08

2 files changed

Lines changed: 38 additions & 7 deletions

File tree

‎packages/remix/src/vite/index.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,22 @@ export function sentryRemixVitePlugin(options: SentryRemixVitePluginOptions = {}
3838
const plugins: Plugin[] = [makeRouteManifestPlugin(options), makeOrchestrionPlugin(options)];
3939

4040
// Uploading from the dev server would create a new set of artifacts on every restart.
41-
if (process.env.NODE_ENV === 'development' || options.sourcemaps?.disable === true) {
41+
if (process.env.NODE_ENV === 'development') {
4242
return plugins;
4343
}
4444

45+
// Added even when source maps are disabled: the bundler plugin also applies bundle size
46+
// optimizations, module metadata, the application key and release management, and it already
47+
// skips the upload itself.
48+
//
4549
// Order matters: Vite passes the already-merged config to every `config` hook, so the deletion
46-
// plugin has to read `build.sourcemap` before `makeEnableSourceMapsPlugin` sets it to 'hidden' -
47-
// otherwise it treats the setting as user-owned and leaves the generated maps on disk.
48-
plugins.push(...makeAddSentryVitePlugin(options), makeEnableSourceMapsPlugin(options));
50+
// plugin has to read `build.sourcemap` before `makeEnableSourceMapsPlugin` sets it to 'hidden'.
51+
plugins.push(...makeAddSentryVitePlugin(options));
52+
53+
// `'disable-upload'` still generates them - debug IDs are injected and the user uploads by hand.
54+
if (options.sourcemaps?.disable !== true) {
55+
plugins.push(makeEnableSourceMapsPlugin(options));
56+
}
4957

5058
return plugins;
5159
}

‎packages/remix/test/vite/index.test.ts‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ vi.mock('@sentry/server-utils/orchestrion/vite', () => ({
2626
sentryOrchestrionPlugin: (options?: { buildTimeInstrumentation?: boolean }) => orchestrionVite(options),
2727
}));
2828

29-
type CapturedSentryOptions = { sourcemaps?: { filesToDeleteAfterUpload?: Promise<unknown> } };
29+
type CapturedSentryOptions = {
30+
applicationKey?: string;
31+
bundleSizeOptimizations?: { excludeTracing?: boolean };
32+
sourcemaps?: { filesToDeleteAfterUpload?: Promise<unknown> };
33+
};
3034

3135
let capturedSentryOptions: CapturedSentryOptions | undefined;
3236

@@ -112,10 +116,29 @@ describe('sentryRemixVitePlugin', () => {
112116
expect(plugins.map(plugin => plugin.name)).toEqual(['sentry-remix-route-manifest', 'code-transformer']);
113117
});
114118

115-
it('leaves out the source map plugins when source maps are disabled', () => {
119+
// Disabling source maps must not drop the bundler plugin: it also applies bundle size
120+
// optimizations, module metadata, the application key and release management, and it skips the
121+
// upload on its own.
122+
it('only drops the source map setting plugin when source maps are disabled', () => {
116123
const plugins = sentryRemixVitePlugin({ sourcemaps: { disable: true } });
117124

118-
expect(plugins.map(plugin => plugin.name)).toEqual(['sentry-remix-route-manifest', 'code-transformer']);
125+
expect(plugins.map(plugin => plugin.name)).toEqual([
126+
'sentry-remix-route-manifest',
127+
'code-transformer',
128+
'sentry-remix-files-to-delete-after-upload',
129+
'sentry-vite-plugin',
130+
]);
131+
});
132+
133+
it('forwards the non-source-map options when source maps are disabled', () => {
134+
sentryRemixVitePlugin({
135+
sourcemaps: { disable: true },
136+
applicationKey: 'my-app-key',
137+
bundleSizeOptimizations: { excludeTracing: true },
138+
});
139+
140+
expect(capturedSentryOptions?.applicationKey).toBe('my-app-key');
141+
expect(capturedSentryOptions?.bundleSizeOptimizations).toEqual({ excludeTracing: true });
119142
});
120143

121144
it('adds an inert orchestrion plugin when `buildTimeInstrumentation` is `false`', () => {

0 commit comments

Comments
 (0)