@@ -365,12 +365,18 @@ describe('withSentryConfig', () => {
365365 process . env . TURBOPACK = '1' ;
366366 vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( '15.3.0' ) ;
367367
368+ // Use a clean config without productionBrowserSourceMaps to ensure it gets auto-enabled
369+ const cleanConfig = { ...exportedNextConfig } ;
370+ delete cleanConfig . productionBrowserSourceMaps ;
371+
368372 const sentryOptions = {
369373 sourcemaps : { } , // no deleteSourcemapsAfterUpload setting
370374 } ;
371375
372- materializeFinalNextConfig ( exportedNextConfig , undefined , sentryOptions ) ;
376+ const finalConfig = materializeFinalNextConfig ( cleanConfig , undefined , sentryOptions ) ;
373377
378+ // Both productionBrowserSourceMaps and deleteSourcemapsAfterUpload should be enabled
379+ expect ( finalConfig . productionBrowserSourceMaps ) . toBe ( true ) ;
374380 expect ( sentryOptions . sourcemaps ) . toHaveProperty ( 'deleteSourcemapsAfterUpload' , true ) ;
375381 } ) ;
376382
@@ -404,6 +410,45 @@ describe('withSentryConfig', () => {
404410 expect ( sentryOptions . sourcemaps ) . not . toHaveProperty ( 'deleteSourcemapsAfterUpload' ) ;
405411 } ) ;
406412
413+ it ( 'does not enable deleteSourcemapsAfterUpload when user pre-configured productionBrowserSourceMaps: true' , ( ) => {
414+ process . env . TURBOPACK = '1' ;
415+ vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( '15.3.0' ) ;
416+
417+ const configWithSourceMapsPreEnabled = {
418+ ...exportedNextConfig ,
419+ productionBrowserSourceMaps : true , // User already enabled
420+ } ;
421+
422+ const sentryOptions = {
423+ sourcemaps : { } , // no explicit deleteSourcemapsAfterUpload setting
424+ } ;
425+
426+ materializeFinalNextConfig ( configWithSourceMapsPreEnabled , undefined , sentryOptions ) ;
427+
428+ // Should NOT automatically enable deletion because productionBrowserSourceMaps was already set by user
429+ expect ( sentryOptions . sourcemaps ) . not . toHaveProperty ( 'deleteSourcemapsAfterUpload' ) ;
430+ } ) ;
431+
432+ it ( 'does not enable sourcemaps or deletion when user explicitly sets productionBrowserSourceMaps: false' , ( ) => {
433+ process . env . TURBOPACK = '1' ;
434+ vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( '15.3.0' ) ;
435+
436+ const configWithSourceMapsDisabled = {
437+ ...exportedNextConfig ,
438+ productionBrowserSourceMaps : false , // User explicitly disabled
439+ } ;
440+
441+ const sentryOptions = {
442+ sourcemaps : { } , // no explicit deleteSourcemapsAfterUpload setting
443+ } ;
444+
445+ const finalConfig = materializeFinalNextConfig ( configWithSourceMapsDisabled , undefined , sentryOptions ) ;
446+
447+ // Should NOT modify productionBrowserSourceMaps or enable deletion when user explicitly set to false
448+ expect ( finalConfig . productionBrowserSourceMaps ) . toBe ( false ) ;
449+ expect ( sentryOptions . sourcemaps ) . not . toHaveProperty ( 'deleteSourcemapsAfterUpload' ) ;
450+ } ) ;
451+
407452 it ( 'logs correct message when enabling sourcemaps for turbopack' , ( ) => {
408453 process . env . TURBOPACK = '1' ;
409454 vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( '15.3.0' ) ;
@@ -426,11 +471,15 @@ describe('withSentryConfig', () => {
426471 vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( '15.3.0' ) ;
427472 const consoleWarnSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
428473
474+ // Use a clean config without productionBrowserSourceMaps to trigger automatic enablement
475+ const cleanConfig = { ...exportedNextConfig } ;
476+ delete cleanConfig . productionBrowserSourceMaps ;
477+
429478 const sentryOptions = {
430479 sourcemaps : { } , // triggers automatic deletion
431480 } ;
432481
433- materializeFinalNextConfig ( exportedNextConfig , undefined , sentryOptions ) ;
482+ materializeFinalNextConfig ( cleanConfig , undefined , sentryOptions ) ;
434483
435484 expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
436485 '[@sentry/nextjs] Source maps will be automatically deleted after being uploaded to Sentry. If you want to keep the source maps, set the `sourcemaps.deleteSourcemapsAfterUpload` option to false in `withSentryConfig()`. If you do not want to generate and upload sourcemaps at all, set the `sourcemaps.disable` option to true.' ,
@@ -517,11 +566,15 @@ describe('withSentryConfig', () => {
517566 process . env . TURBOPACK = '1' ;
518567 vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( '15.3.0' ) ;
519568
569+ // Use a clean config without productionBrowserSourceMaps to trigger automatic enablement
570+ const cleanConfig = { ...exportedNextConfig } ;
571+ delete cleanConfig . productionBrowserSourceMaps ;
572+
520573 const sentryOptions = {
521574 sourcemaps : { } , // empty object
522575 } ;
523576
524- materializeFinalNextConfig ( exportedNextConfig , undefined , sentryOptions ) ;
577+ materializeFinalNextConfig ( cleanConfig , undefined , sentryOptions ) ;
525578
526579 expect ( sentryOptions . sourcemaps ) . toHaveProperty ( 'deleteSourcemapsAfterUpload' , true ) ;
527580 } ) ;
@@ -551,12 +604,16 @@ describe('withSentryConfig', () => {
551604 process . env . TURBOPACK = '1' ;
552605 vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( '15.3.0' ) ;
553606
607+ // Use a clean config without productionBrowserSourceMaps to trigger automatic enablement
608+ const cleanConfig = { ...exportedNextConfig } ;
609+ delete cleanConfig . productionBrowserSourceMaps ;
610+
554611 const sentryOptions = {
555612 tunnelRoute : '/custom-tunnel' ,
556613 sourcemaps : { } ,
557614 } ;
558615
559- const finalConfig = materializeFinalNextConfig ( exportedNextConfig , undefined , sentryOptions ) ;
616+ const finalConfig = materializeFinalNextConfig ( cleanConfig , undefined , sentryOptions ) ;
560617
561618 expect ( finalConfig . productionBrowserSourceMaps ) . toBe ( true ) ;
562619 expect ( sentryOptions . sourcemaps ) . toHaveProperty ( 'deleteSourcemapsAfterUpload' , true ) ;
@@ -573,6 +630,7 @@ describe('withSentryConfig', () => {
573630
574631 const cleanConfig = { ...exportedNextConfig } ;
575632 delete cleanConfig . env ;
633+ delete cleanConfig . productionBrowserSourceMaps ; // Ensure it gets auto-enabled
576634
577635 const sentryOptions = {
578636 release : {
0 commit comments