Skip to content

Commit f7d1ffd

Browse files
committed
again?
1 parent de9943d commit f7d1ffd

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

packages/nextjs/src/client/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const globalWithInjectedValues = GLOBAL_OBJ as typeof GLOBAL_OBJ & {
4343
_sentryBasePath?: string;
4444
_sentryRelease?: string;
4545
_experimentalThirdPartyOriginStackFrames?: string;
46+
_sentrySpotlight?: string;
4647
};
4748

4849
// Treeshakable guard to remove all code related to tracing
@@ -143,10 +144,9 @@ function getDefaultIntegrations(options: BrowserOptions): Integration[] {
143144
);
144145

145146
// 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;
147+
// The value is injected at build time via the valueInjectionLoader because
148+
// our SDK code in node_modules is not processed by Next.js DefinePlugin
149+
const spotlightEnvValue = globalWithInjectedValues._sentrySpotlight;
150150
if (spotlightEnvValue !== undefined && options.spotlight === undefined) {
151151
const boolValue = envToBool(spotlightEnvValue, { strict: true });
152152
const spotlightConfig = boolValue !== null ? boolValue : spotlightEnvValue;

packages/nextjs/src/config/turbopack/constructTurbopackConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export function constructTurbopackConfig({
4545
routeManifest,
4646
nextJsVersion,
4747
tunnelPath,
48+
userNextConfig,
4849
});
4950

5051
for (const { matcher, rule } of valueInjectionRules) {

packages/nextjs/src/config/turbopack/generateValueInjectionRules.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from 'path';
22
import type { RouteManifest } from '../manifest/types';
3-
import type { JSONValue, TurbopackMatcherWithRule } from '../types';
3+
import type { JSONValue, NextConfigObject, TurbopackMatcherWithRule } from '../types';
44

55
/**
66
* Generate the value injection rules for client and server in turbopack config.
@@ -9,10 +9,12 @@ export function generateValueInjectionRules({
99
routeManifest,
1010
nextJsVersion,
1111
tunnelPath,
12+
userNextConfig,
1213
}: {
1314
routeManifest?: RouteManifest;
1415
nextJsVersion?: string;
1516
tunnelPath?: string;
17+
userNextConfig?: NextConfigObject;
1618
}): TurbopackMatcherWithRule[] {
1719
const rules: TurbopackMatcherWithRule[] = [];
1820
const isomorphicValues: Record<string, JSONValue> = {};
@@ -28,6 +30,14 @@ export function generateValueInjectionRules({
2830
clientValues._sentryRouteManifest = JSON.stringify(routeManifest);
2931
}
3032

33+
// Inject Spotlight config from NEXT_PUBLIC_SENTRY_SPOTLIGHT
34+
// Turbopack is only used in dev mode, so we always inject this
35+
// We check both userNextConfig.env (from next.config.js) and process.env (from .env files or shell)
36+
const spotlightValue = userNextConfig?.env?.NEXT_PUBLIC_SENTRY_SPOTLIGHT ?? process.env.NEXT_PUBLIC_SENTRY_SPOTLIGHT;
37+
if (spotlightValue) {
38+
clientValues._sentrySpotlight = spotlightValue;
39+
}
40+
3141
// Inject tunnel route path for both client and server
3242
if (tunnelPath) {
3343
isomorphicValues._sentryRewritesTunnelPath = tunnelPath;

packages/nextjs/src/config/webpack.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,12 @@ function addValueInjectionLoader({
763763
? 'true'
764764
: undefined,
765765
_sentryRouteManifest: JSON.stringify(routeManifest),
766+
// Inject Spotlight config from NEXT_PUBLIC_SENTRY_SPOTLIGHT (only in dev mode)
767+
// This is needed because our SDK code in node_modules is not processed by Next.js DefinePlugin
768+
// We check both userNextConfig.env (from next.config.js) and process.env (from .env files or shell)
769+
_sentrySpotlight: buildContext.dev
770+
? (userNextConfig.env?.NEXT_PUBLIC_SENTRY_SPOTLIGHT ?? process.env.NEXT_PUBLIC_SENTRY_SPOTLIGHT)
771+
: undefined,
766772
};
767773

768774
if (buildContext.isServer) {

0 commit comments

Comments
 (0)