From 74c5fb3f01daa1da938e50fb99c6937fdee49d24 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Mon, 7 Apr 2025 12:58:45 +0200 Subject: [PATCH 1/3] feat(nextjs): Un experimentify `clientInstrumentationHook` They actually unexperimentified it https://github.com/vercel/next.js/commit/2737373c3b554cba304a0af03383636bba5086e2 --- CHANGELOG.md | 2 +- packages/nextjs/src/config/types.ts | 1 - packages/nextjs/src/config/webpack.ts | 2 +- .../nextjs/src/config/withSentryConfig.ts | 20 +------------------ 4 files changed, 3 insertions(+), 22 deletions(-) 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/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..28ea4c982417 100644 --- a/packages/nextjs/src/config/withSentryConfig.ts +++ b/packages/nextjs/src/config/withSentryConfig.ts @@ -176,12 +176,7 @@ function getFinalConfigObject( parseInt(prerelease.split('.')[1] || '', 10) >= 8; 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 { From 338775f146c4e92fd602f82e6a04944a3968fcdd Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Mon, 7 Apr 2025 13:00:13 +0200 Subject: [PATCH 2/3] . --- packages/nextjs/src/config/withSentryConfig.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nextjs/src/config/withSentryConfig.ts b/packages/nextjs/src/config/withSentryConfig.ts index 28ea4c982417..ef1efa0fc90a 100644 --- a/packages/nextjs/src/config/withSentryConfig.ts +++ b/packages/nextjs/src/config/withSentryConfig.ts @@ -173,7 +173,7 @@ 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 && process.env.TURBOPACK) { From e0ef5540caf3dfbc4a03af7545ebd508418942aa Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Mon, 7 Apr 2025 13:11:10 +0200 Subject: [PATCH 3/3] bump --- .../e2e-tests/test-applications/nextjs-turbo/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"