Skip to content

Commit 7c1107f

Browse files
committed
fix(nextjs): Use valueInjectionLoader for Spotlight config instead of DefinePlugin
DefinePlugin only performs static text replacement and doesn't work with the SDK's dynamic property access (process.env[key]). Instead, use the existing valueInjectionLoader to inject Spotlight config into globalThis, which the browser SDK already checks as a fallback.
1 parent 693c80e commit 7c1107f

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export function constructWebpackConfigFunction({
108108
releaseName,
109109
routeManifest,
110110
nextJsVersion,
111+
spotlightConfig,
111112
});
112113

113114
addOtelWarningIgnoreRule(newConfig);
@@ -447,18 +448,6 @@ export function constructWebpackConfigFunction({
447448
}),
448449
);
449450

450-
// Inject Spotlight config for client builds so the browser SDK can auto-enable Spotlight.
451-
// Next.js doesn't replace process.env.NEXT_PUBLIC_* in node_modules code, so we use
452-
// DefinePlugin to inject the value directly. The browser SDK's getSpotlightConfig()
453-
// already checks for NEXT_PUBLIC_SENTRY_SPOTLIGHT.
454-
if (runtime === 'client' && spotlightConfig) {
455-
newConfig.plugins.push(
456-
new buildContext.webpack.DefinePlugin({
457-
'process.env.NEXT_PUBLIC_SENTRY_SPOTLIGHT': JSON.stringify(spotlightConfig),
458-
}),
459-
);
460-
}
461-
462451
return newConfig;
463452
};
464453
}
@@ -725,6 +714,7 @@ function addValueInjectionLoader({
725714
releaseName,
726715
routeManifest,
727716
nextJsVersion,
717+
spotlightConfig,
728718
}: {
729719
newConfig: WebpackConfigObjectWithModuleRules;
730720
userNextConfig: NextConfigObject;
@@ -733,6 +723,7 @@ function addValueInjectionLoader({
733723
releaseName: string | undefined;
734724
routeManifest: RouteManifest | undefined;
735725
nextJsVersion: string | undefined;
726+
spotlightConfig: string | undefined;
736727
}): void {
737728
const assetPrefix = userNextConfig.assetPrefix || userNextConfig.basePath || '';
738729

@@ -777,6 +768,9 @@ function addValueInjectionLoader({
777768
? 'true'
778769
: undefined,
779770
_sentryRouteManifest: JSON.stringify(routeManifest),
771+
// Inject Spotlight config so the browser SDK can auto-enable Spotlight.
772+
// The browser SDK's getEnvValue() checks globalThis as a fallback for bundler-injected values.
773+
NEXT_PUBLIC_SENTRY_SPOTLIGHT: spotlightConfig,
780774
};
781775

782776
if (buildContext.isServer) {

0 commit comments

Comments
 (0)