diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ee0047124ff..f85aa9a477a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -119,7 +119,7 @@ Work in this release was contributed by @Page-. Thank you for your contribution! - **feat(nextjs): Support `instrumentation-client.ts` ([#15705](https://github.com/getsentry/sentry-javascript/pull/15705))** - Next.js recently added a feature to support [client-side (browser) instrumentation via the `experimental.clientInstrumentationHook` flag and the `instrumentation-client.ts` file](https://nextjs.org/docs/app/api-reference/config/next-config-js/clientInstrumentationHook). + Next.js recently added a feature to support [client-side (browser) instrumentation via a `instrumentation-client.ts` file](https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation-client). To be forwards compatible, the Sentry Next.js SDK will now pick up `instrumentation-client.ts` files even on older Next.js versions and add them to your client bundles. It is suggested that you either rename your `sentry.client.config.ts` file to `instrumentation-client.ts`, or if you already happen to have a `instrumentation-client.ts` file move the contents of `sentry.client.config.ts` to `instrumentation-client.ts`. diff --git a/dev-packages/e2e-tests/test-applications/nextjs-turbo/package.json b/dev-packages/e2e-tests/test-applications/nextjs-turbo/package.json index 94e762a859a9..99679ba13deb 100644 --- a/dev-packages/e2e-tests/test-applications/nextjs-turbo/package.json +++ b/dev-packages/e2e-tests/test-applications/nextjs-turbo/package.json @@ -17,7 +17,7 @@ "@types/node": "^18.19.1", "@types/react": "18.0.26", "@types/react-dom": "18.0.9", - "next": "15.3.0-canary.26", + "next": "15.3.0-canary.40", "react": "rc", "react-dom": "rc", "typescript": "~5.0.0" diff --git a/packages/nextjs/src/config/types.ts b/packages/nextjs/src/config/types.ts index 95c15b887573..965233d08b76 100644 --- a/packages/nextjs/src/config/types.ts +++ b/packages/nextjs/src/config/types.ts @@ -44,7 +44,6 @@ export type NextConfigObject = { // Next.js experimental options experimental?: { instrumentationHook?: boolean; - clientInstrumentationHook?: boolean; clientTraceMetadata?: string[]; }; productionBrowserSourceMaps?: boolean; diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 9155b0cd2b60..af7e40f5b58c 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -344,7 +344,7 @@ export function constructWebpackConfigFunction( if (clientSentryConfigFileName) { // eslint-disable-next-line no-console console.warn( - `[@sentry/nextjs] DEPRECATION WARNING: It is recommended renaming your \`${clientSentryConfigFileName}\` file, or moving its content to \`instrumentation-client.ts\`. When using Turbopack \`${clientSentryConfigFileName}\` will no longer work. Read more about the \`instrumentation-client.ts\` file: https://nextjs.org/docs/app/api-reference/config/next-config-js/clientInstrumentationHook`, + `[@sentry/nextjs] DEPRECATION WARNING: It is recommended renaming your \`${clientSentryConfigFileName}\` file, or moving its content to \`instrumentation-client.ts\`. When using Turbopack \`${clientSentryConfigFileName}\` will no longer work. Read more about the \`instrumentation-client.ts\` file: https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation-client`, ); } } diff --git a/packages/nextjs/src/config/withSentryConfig.ts b/packages/nextjs/src/config/withSentryConfig.ts index 4b24d8370393..ef1efa0fc90a 100644 --- a/packages/nextjs/src/config/withSentryConfig.ts +++ b/packages/nextjs/src/config/withSentryConfig.ts @@ -173,15 +173,10 @@ function getFinalConfigObject( minor === 3 && patch === 0 && prerelease.startsWith('canary.') && - parseInt(prerelease.split('.')[1] || '', 10) >= 8; + parseInt(prerelease.split('.')[1] || '', 10) >= 28; const supportsClientInstrumentation = isSupportedCanary || isSupportedVersion; - if (supportsClientInstrumentation) { - incomingUserNextConfigObject.experimental = { - clientInstrumentationHook: true, - ...incomingUserNextConfigObject.experimental, - }; - } else if (process.env.TURBOPACK) { + if (!supportsClientInstrumentation && process.env.TURBOPACK) { if (process.env.NODE_ENV === 'development') { // eslint-disable-next-line no-console console.warn( @@ -194,19 +189,6 @@ function getFinalConfigObject( ); } } - } else { - // If we cannot detect a Next.js version for whatever reason, the sensible default is still to set the `experimental.instrumentationHook`. - incomingUserNextConfigObject.experimental = { - clientInstrumentationHook: true, - ...incomingUserNextConfigObject.experimental, - }; - } - - if (incomingUserNextConfigObject.experimental?.clientInstrumentationHook === false) { - // eslint-disable-next-line no-console - console.warn( - '[@sentry/nextjs] WARNING: You set the `experimental.clientInstrumentationHook` option to `false`. Note that Sentry will not be initialized if you did not set it up inside `instrumentation-client.(js|ts)`.', - ); } return {