Skip to content

Commit de658a8

Browse files
authored
fix(nextjs): Turn off debugID injection if sourcemaps are explicitly disabled (#19010)
This PR adds an additional check to make sure we only inject debug IDs if sourcemaps are NOT disabled. The issue isn't present when sourcemaps are enabled and since debug IDs are only relevant for sourcemap correlation then this should be a safe change AFAIK. Closes #18983
1 parent 23133dc commit de658a8

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

packages/nextjs/src/config/handleRunAfterProductionCompile.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export async function handleRunAfterProductionCompile(
5050
await sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal();
5151
await sentryBuildPluginManager.createRelease();
5252

53-
if (!usesNativeDebugIds) {
53+
// Skip debug ID injection if sourcemaps are disabled which are only relevant for sourcemap correlation
54+
if (!usesNativeDebugIds && sentryBuildOptions.sourcemaps?.disable !== true) {
5455
await sentryBuildPluginManager.injectDebugIds([distDir]);
5556
}
5657

packages/nextjs/test/config/handleRunAfterProductionCompile.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,62 @@ describe('handleRunAfterProductionCompile', () => {
249249
});
250250
});
251251

252+
describe('sourcemaps disabled', () => {
253+
it('skips debug ID injection when sourcemaps.disable is true', async () => {
254+
const optionsWithDisabledSourcemaps: SentryBuildOptions = {
255+
...mockSentryBuildOptions,
256+
sourcemaps: {
257+
disable: true,
258+
},
259+
};
260+
261+
await handleRunAfterProductionCompile(
262+
{
263+
releaseName: 'test-release',
264+
distDir: '/path/to/.next',
265+
buildTool: 'turbopack',
266+
},
267+
optionsWithDisabledSourcemaps,
268+
);
269+
270+
expect(mockSentryBuildPluginManager.injectDebugIds).not.toHaveBeenCalled();
271+
expect(mockSentryBuildPluginManager.uploadSourcemaps).toHaveBeenCalled();
272+
});
273+
274+
it('still injects debug IDs when sourcemaps.disable is false', async () => {
275+
const optionsWithEnabledSourcemaps: SentryBuildOptions = {
276+
...mockSentryBuildOptions,
277+
sourcemaps: {
278+
disable: false,
279+
},
280+
};
281+
282+
await handleRunAfterProductionCompile(
283+
{
284+
releaseName: 'test-release',
285+
distDir: '/path/to/.next',
286+
buildTool: 'turbopack',
287+
},
288+
optionsWithEnabledSourcemaps,
289+
);
290+
291+
expect(mockSentryBuildPluginManager.injectDebugIds).toHaveBeenCalledWith(['/path/to/.next']);
292+
});
293+
294+
it('still injects debug IDs when sourcemaps option is undefined', async () => {
295+
await handleRunAfterProductionCompile(
296+
{
297+
releaseName: 'test-release',
298+
distDir: '/path/to/.next',
299+
buildTool: 'turbopack',
300+
},
301+
mockSentryBuildOptions,
302+
);
303+
304+
expect(mockSentryBuildPluginManager.injectDebugIds).toHaveBeenCalledWith(['/path/to/.next']);
305+
});
306+
});
307+
252308
describe('path handling', () => {
253309
it('correctly passes distDir to debug ID injection', async () => {
254310
const customDistDir = '/custom/dist/path';

0 commit comments

Comments
 (0)