Skip to content

Commit a67de9f

Browse files
authored
Merge branch 'develop' into timfish/fix/improve-uuid-perf
2 parents 7c3ae66 + 1bd76c0 commit a67de9f

File tree

8 files changed

+233
-706
lines changed

8 files changed

+233
-706
lines changed

dev-packages/e2e-tests/test-applications/ember-classic/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@
7575
"node": ">=18"
7676
},
7777
"resolutions": {
78-
"@babel/traverse": "~7.25.9"
78+
"@babel/traverse": "~7.25.9",
79+
"clean-css": "^5.3.0"
7980
},
8081
"ember": {
8182
"edition": "octane"

dev-packages/e2e-tests/test-applications/nextjs-16/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"test:build-canary": "pnpm install && pnpm add next@canary && pnpm build",
1919
"test:build-canary-webpack": "pnpm install && pnpm add next@canary && pnpm build-webpack",
2020
"test:assert": "pnpm test:prod && pnpm test:dev",
21-
"test:assert-webpack": "pnpm test:prod"
21+
"test:assert-webpack": "pnpm test:prod && pnpm test:dev-webpack"
2222
},
2323
"dependencies": {
2424
"@sentry/nextjs": "latest || *",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
"jsdom": "^21.1.2",
125125
"lerna": "7.1.1",
126126
"madge": "7.0.0",
127-
"nodemon": "^2.0.16",
127+
"nodemon": "^3.1.10",
128128
"npm-run-all2": "^6.2.0",
129129
"prettier": "^3.6.2",
130130
"prettier-plugin-astro": "^0.14.1",

packages/nextjs/src/config/util.ts

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -109,66 +109,75 @@ export function supportsNativeDebugIds(version: string): boolean {
109109
}
110110

111111
/**
112-
* Checks if the current Next.js version uses Turbopack as the default bundler.
113-
* Starting from Next.js 15.6.0-canary.38, turbopack became the default for `next build`.
112+
* Checks if the given Next.js version requires the `experimental.instrumentationHook` option.
113+
* Next.js 15.0.0 and higher (including certain RC and canary versions) no longer require this option
114+
* and will print a warning if it is set.
114115
*
115-
* @param version - Next.js version string to check.
116-
* @returns true if the version uses Turbopack by default
116+
* @param version - version string to check.
117+
* @returns true if the version requires the instrumentationHook option to be set
117118
*/
118-
export function isTurbopackDefaultForVersion(version: string): boolean {
119+
export function requiresInstrumentationHook(version: string): boolean {
119120
if (!version) {
120-
return false;
121+
return true; // Default to requiring it if version cannot be determined
121122
}
122123

123-
const { major, minor, prerelease } = parseSemver(version);
124+
const { major, minor, patch, prerelease } = parseSemver(version);
124125

125-
if (major === undefined || minor === undefined) {
126-
return false;
126+
if (major === undefined || minor === undefined || patch === undefined) {
127+
return true; // Default to requiring it if parsing fails
127128
}
128129

129-
// Next.js 16+ uses turbopack by default
130+
// Next.js 16+ never requires the hook
130131
if (major >= 16) {
132+
return false;
133+
}
134+
135+
// Next.js 14 and below always require the hook
136+
if (major < 15) {
131137
return true;
132138
}
133139

134-
// For Next.js 15, only canary versions 15.6.0-canary.40+ use turbopack by default
135-
// Stable 15.x releases still use webpack by default
136-
if (major === 15 && minor >= 6 && prerelease && prerelease.startsWith('canary.')) {
137-
if (minor >= 7) {
138-
return true;
139-
}
140+
// At this point, we know it's Next.js 15.x.y
141+
// Stable releases (15.0.0+) don't require the hook
142+
if (!prerelease) {
143+
return false;
144+
}
145+
146+
// Next.js 15.x.y with x > 0 or y > 0 don't require the hook
147+
if (minor > 0 || patch > 0) {
148+
return false;
149+
}
150+
151+
// Check specific prerelease versions that don't require the hook
152+
if (prerelease.startsWith('rc.')) {
153+
const rcNumber = parseInt(prerelease.split('.')[1] || '0', 10);
154+
return rcNumber === 0; // Only rc.0 requires the hook
155+
}
156+
157+
if (prerelease.startsWith('canary.')) {
140158
const canaryNumber = parseInt(prerelease.split('.')[1] || '0', 10);
141-
if (canaryNumber >= 40) {
142-
return true;
143-
}
159+
return canaryNumber < 124; // canary.124+ doesn't require the hook
144160
}
145161

146-
return false;
162+
// All other 15.0.0 prerelease versions (alpha, beta, etc.) require the hook
163+
return true;
147164
}
148165

149166
/**
150167
* Determines which bundler is actually being used based on environment variables,
151-
* CLI flags, and Next.js version.
168+
* and CLI flags.
152169
*
153-
* @param nextJsVersion - The Next.js version string
154-
* @returns 'turbopack', 'webpack', or undefined if it cannot be determined
170+
* @returns 'turbopack' or 'webpack'
155171
*/
156-
export function detectActiveBundler(nextJsVersion: string | undefined): 'turbopack' | 'webpack' | undefined {
157-
if (process.env.TURBOPACK || process.argv.includes('--turbo')) {
158-
return 'turbopack';
159-
}
172+
export function detectActiveBundler(): 'turbopack' | 'webpack' {
173+
const turbopackEnv = process.env.TURBOPACK;
160174

161-
// Explicit opt-in to webpack via --webpack flag
162-
if (process.argv.includes('--webpack')) {
163-
return 'webpack';
164-
}
175+
// Check if TURBOPACK env var is set to a truthy value (excluding falsy strings like 'false', '0', '')
176+
const isTurbopackEnabled = turbopackEnv && turbopackEnv !== 'false' && turbopackEnv !== '0';
165177

166-
// Fallback to version-based default behavior
167-
if (nextJsVersion) {
168-
const turbopackIsDefault = isTurbopackDefaultForVersion(nextJsVersion);
169-
return turbopackIsDefault ? 'turbopack' : 'webpack';
178+
if (isTurbopackEnabled || process.argv.includes('--turbo')) {
179+
return 'turbopack';
180+
} else {
181+
return 'webpack';
170182
}
171-
172-
// Unlikely but at this point, we just assume webpack for older behavior
173-
return 'webpack';
174183
}

packages/nextjs/src/config/withSentryConfig.ts

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ import type {
1616
SentryBuildOptions,
1717
TurbopackOptions,
1818
} from './types';
19-
import { detectActiveBundler, getNextjsVersion, supportsProductionCompileHook } from './util';
19+
import {
20+
detectActiveBundler,
21+
getNextjsVersion,
22+
requiresInstrumentationHook,
23+
supportsProductionCompileHook,
24+
} from './util';
2025
import { constructWebpackConfigFunction } from './webpack';
2126

2227
let showedExportModeTunnelWarning = false;
@@ -178,47 +183,18 @@ function getFinalConfigObject(
178183

179184
// From Next.js version (15.0.0-canary.124) onwards, Next.js does no longer require the `experimental.instrumentationHook` option and will
180185
// print a warning when it is set, so we need to conditionally provide it for lower versions.
181-
if (nextJsVersion) {
182-
const { major, minor, patch, prerelease } = parseSemver(nextJsVersion);
183-
const isFullySupportedRelease =
184-
major !== undefined &&
185-
minor !== undefined &&
186-
patch !== undefined &&
187-
major >= 15 &&
188-
((minor === 0 && patch === 0 && prerelease === undefined) || minor > 0 || patch > 0);
189-
const isSupportedV15Rc =
190-
major !== undefined &&
191-
minor !== undefined &&
192-
patch !== undefined &&
193-
prerelease !== undefined &&
194-
major === 15 &&
195-
minor === 0 &&
196-
patch === 0 &&
197-
prerelease.startsWith('rc.') &&
198-
parseInt(prerelease.split('.')[1] || '', 10) > 0;
199-
const isSupportedCanary =
200-
minor !== undefined &&
201-
patch !== undefined &&
202-
prerelease !== undefined &&
203-
major === 15 &&
204-
minor === 0 &&
205-
patch === 0 &&
206-
prerelease.startsWith('canary.') &&
207-
parseInt(prerelease.split('.')[1] || '', 10) >= 124;
208-
209-
if (!isFullySupportedRelease && !isSupportedV15Rc && !isSupportedCanary) {
210-
if (incomingUserNextConfigObject.experimental?.instrumentationHook === false) {
211-
// eslint-disable-next-line no-console
212-
console.warn(
213-
'[@sentry/nextjs] You turned off the `experimental.instrumentationHook` option. Note that Sentry will not be initialized if you did not set it up inside `instrumentation.(js|ts)`.',
214-
);
215-
}
216-
incomingUserNextConfigObject.experimental = {
217-
instrumentationHook: true,
218-
...incomingUserNextConfigObject.experimental,
219-
};
186+
if (nextJsVersion && requiresInstrumentationHook(nextJsVersion)) {
187+
if (incomingUserNextConfigObject.experimental?.instrumentationHook === false) {
188+
// eslint-disable-next-line no-console
189+
console.warn(
190+
'[@sentry/nextjs] You turned off the `experimental.instrumentationHook` option. Note that Sentry will not be initialized if you did not set it up inside `instrumentation.(js|ts)`.',
191+
);
220192
}
221-
} else {
193+
incomingUserNextConfigObject.experimental = {
194+
instrumentationHook: true,
195+
...incomingUserNextConfigObject.experimental,
196+
};
197+
} else if (!nextJsVersion) {
222198
// If we cannot detect a Next.js version for whatever reason, the sensible default is to set the `experimental.instrumentationHook`, even though it may create a warning.
223199
if (
224200
incomingUserNextConfigObject.experimental &&
@@ -261,7 +237,7 @@ function getFinalConfigObject(
261237
nextMajor = major;
262238
}
263239

264-
const activeBundler = detectActiveBundler(nextJsVersion);
240+
const activeBundler = detectActiveBundler();
265241
const isTurbopack = activeBundler === 'turbopack';
266242
const isWebpack = activeBundler === 'webpack';
267243
const isTurbopackSupported = supportsProductionCompileHook(nextJsVersion ?? '');

0 commit comments

Comments
 (0)