@@ -73,26 +73,6 @@ export function init(options: BrowserOptions): Client | undefined {
7373 ...options ,
7474 } ;
7575
76- // Auto-enable Spotlight in development mode from NEXT_PUBLIC_SENTRY_SPOTLIGHT env var
77- // This code will be tree-shaken in production builds by Next.js
78- if ( process . env . NODE_ENV === 'development' ) {
79- const envValue = process . env . NEXT_PUBLIC_SENTRY_SPOTLIGHT ;
80- // Only apply env var if user hasn't explicitly set spotlight option
81- if ( envValue !== undefined && options . spotlight === undefined ) {
82- const boolValue = envToBool ( envValue , { strict : true } ) ;
83- const spotlightConfig = boolValue !== null ? boolValue : envValue ;
84- const spotlightValue = resolveSpotlightOptions ( undefined , spotlightConfig ) ;
85-
86- if ( spotlightValue ) {
87- const spotlightArgs = typeof spotlightValue === 'string' ? { sidecarUrl : spotlightValue } : undefined ;
88- opts . integrations = [
89- ...( Array . isArray ( opts . integrations ) ? opts . integrations : [ ] ) ,
90- spotlightBrowserIntegration ( spotlightArgs ) ,
91- ] ;
92- }
93- }
94- }
95-
9676 applyTunnelRouteOption ( opts ) ;
9777 applySdkMetadata ( opts , 'nextjs' , [ 'nextjs' , 'react' ] ) ;
9878
@@ -162,6 +142,22 @@ function getDefaultIntegrations(options: BrowserOptions): Integration[] {
162142 } ) ,
163143 ) ;
164144
145+ // Auto-enable Spotlight from NEXT_PUBLIC_SENTRY_SPOTLIGHT env var
146+ // Next.js replaces process.env.NEXT_PUBLIC_* at build time, so this will be
147+ // a string literal if set, or undefined if not set. When undefined, this entire
148+ // block is dead code and will be removed by the bundler.
149+ const spotlightEnvValue = process . env . NEXT_PUBLIC_SENTRY_SPOTLIGHT ;
150+ if ( spotlightEnvValue !== undefined && options . spotlight === undefined ) {
151+ const boolValue = envToBool ( spotlightEnvValue , { strict : true } ) ;
152+ const spotlightConfig = boolValue !== null ? boolValue : spotlightEnvValue ;
153+ const spotlightValue = resolveSpotlightOptions ( undefined , spotlightConfig ) ;
154+
155+ if ( spotlightValue ) {
156+ const spotlightArgs = typeof spotlightValue === 'string' ? { sidecarUrl : spotlightValue } : undefined ;
157+ customDefaultIntegrations . push ( spotlightBrowserIntegration ( spotlightArgs ) ) ;
158+ }
159+ }
160+
165161 return customDefaultIntegrations ;
166162}
167163
0 commit comments