Skip to content

Commit 1acf54f

Browse files
authored
feat(nextjs): Bump minimum required Next.js version to 13.2.0 (#11097)
1 parent 557d846 commit 1acf54f

15 files changed

+240
-616
lines changed

MIGRATION.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,11 @@ The following previously deprecated API has been removed from the `@sentry/nextj
630630
- `IS_BUILD`
631631
- `isBuild`
632632

633+
#### Updated minimum compatible Next.js version to `13.2.0`
634+
635+
The minimum version of Next.js compatible with the Sentry Next.js SDK has been raised to `13.2.0`. Older versions may
636+
exhibit bugs or unexpected behaviour.
637+
633638
#### Merging of the Sentry Webpack Plugin options and SDK Build options
634639

635640
With version 8 of the Sentry Next.js SDK, `withSentryConfig` will no longer accept 3 arguments. The second argument

packages/nextjs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@
5252
"@types/resolve": "1.20.3",
5353
"@types/webpack": "^4.41.31",
5454
"eslint-plugin-react": "^7.31.11",
55-
"next": "10.1.3"
55+
"next": "13.2.0"
5656
},
5757
"peerDependencies": {
58-
"next": "^10.0.8 || ^11.0 || ^12.0 || ^13.0 || ^14.0",
58+
"next": "^13.2.0 || ^14.0",
5959
"react": "16.x || 17.x || 18.x",
6060
"webpack": ">= 4.0.0"
6161
},

packages/nextjs/src/client/routing/pagesRouterRoutingInstrumentation.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
import { WINDOW, startBrowserTracingNavigationSpan, startBrowserTracingPageLoadSpan } from '@sentry/react';
88
import type { Client, TransactionSource } from '@sentry/types';
99
import { browserPerformanceTimeOrigin, logger, stripUrlQueryAndFragment } from '@sentry/utils';
10-
import type { NEXT_DATA as NextData } from 'next/dist/next-server/lib/utils';
10+
11+
import type { NEXT_DATA } from 'next/dist/shared/lib/utils';
1112
import RouterImport from 'next/router';
1213

1314
// next/router v10 is CJS
@@ -27,7 +28,7 @@ const globalObject = WINDOW as typeof WINDOW & {
2728
/**
2829
* Describes data located in the __NEXT_DATA__ script tag. This tag is present on every page of a Next.js app.
2930
*/
30-
interface SentryEnhancedNextData extends NextData {
31+
interface SentryEnhancedNextData extends NEXT_DATA {
3132
props: {
3233
pageProps?: {
3334
_sentryTraceData?: string; // trace parent info, if injected by a data-fetcher

packages/nextjs/src/common/wrapGetServerSidePropsWithSentry.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ export function wrapGetServerSidePropsWithSentry(
4848
const activeSpan = getActiveSpan();
4949
const requestTransaction = getSpanFromRequest(req) ?? (activeSpan ? getRootSpan(activeSpan) : undefined);
5050
if (requestTransaction) {
51-
serverSideProps.props._sentryTraceData = spanToTraceHeader(requestTransaction);
51+
(serverSideProps.props as Record<string, unknown>)._sentryTraceData = spanToTraceHeader(requestTransaction);
5252

5353
const dynamicSamplingContext = getDynamicSamplingContextFromSpan(requestTransaction);
54-
serverSideProps.props._sentryBaggage = dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext);
54+
(serverSideProps.props as Record<string, unknown>)._sentryBaggage =
55+
dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext);
5556
}
5657
}
5758

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
/// <reference types="next/navigation-types/compat/navigation" />
34

45
// NOTE: This file should not be edited
56
// see https://nextjs.org/docs/basic-features/typescript for more information.

packages/nextjs/test/integration/next10.config.template

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/nextjs/test/integration/next11.config.template

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/nextjs/test/integration/next12.config.template

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/nextjs/test/integration/next13.appdir.config.template

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ const moduleExports = {
44
eslint: {
55
ignoreDuringBuilds: true,
66
},
7-
experimental: {
8-
appDir: Number(process.env.NODE_MAJOR) >= 16, // experimental.appDir requires Node v16.8.0 or later.
9-
},
107
pageExtensions: ['jsx', 'js', 'tsx', 'ts', 'page.tsx'],
118
};
129

packages/nextjs/test/integration/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"dependencies": {
1414
"@sentry/nextjs": "file:../../",
1515
"next": "latest",
16-
"react": "^17.0.1",
17-
"react-dom": "^17.0.1"
16+
"react": "^18.2.0",
17+
"react-dom": "^18.2.0"
1818
},
1919
"devDependencies": {
2020
"@types/node": "^15.3.1",

packages/nextjs/test/performance/pagesRouterInstrumentation.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { WINDOW } from '@sentry/react';
22
import type { Client } from '@sentry/types';
33
import { JSDOM } from 'jsdom';
4-
import type { NEXT_DATA as NextData } from 'next/dist/next-server/lib/utils';
4+
import type { NEXT_DATA } from 'next/dist/shared/lib/utils';
55
import Router from 'next/router';
66

77
import {
@@ -60,7 +60,7 @@ describe('pagesRouterInstrumentPageLoad', () => {
6060
navigatableRoutes?: string[];
6161
hasNextData: boolean;
6262
}) {
63-
const nextDataContent: NextData = {
63+
const nextDataContent: NEXT_DATA = {
6464
props: pageProperties.props,
6565
page: pageProperties.route,
6666
query: pageProperties.query,
@@ -222,7 +222,7 @@ describe('pagesRouterInstrumentNavigation', () => {
222222
navigatableRoutes?: string[];
223223
hasNextData: boolean;
224224
}) {
225-
const nextDataContent: NextData = {
225+
const nextDataContent: NEXT_DATA = {
226226
props: pageProperties.props,
227227
page: pageProperties.route,
228228
query: pageProperties.query,

packages/nextjs/test/run-integration-tests.sh

Lines changed: 33 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ echo "Running integration tests on Node $NODE_VERSION"
3131
# make a backup of our config file so we can restore it when we're done
3232
mv next.config.js next.config.js.bak
3333

34-
for NEXTJS_VERSION in 10 11 12 13; do
34+
for NEXTJS_VERSION in 13; do
3535
for USE_APPDIR in true false; do
36-
if ([ "$NEXTJS_VERSION" -lt "13" ] || [ "$NODE_MAJOR" -lt "16" ]) && [ "$USE_APPDIR" == true ]; then
37-
# App dir doesn not work on Next.js < 13 or Node.js < 16
36+
if ([ "$NODE_MAJOR" -lt "16" ]) && [ "$USE_APPDIR" == true ]; then
37+
# App dir doesn not work on Node.js < 16
3838
continue
3939
fi
4040

@@ -64,11 +64,6 @@ for NEXTJS_VERSION in 10 11 12 13; do
6464
sed -i /"next.*latest"/s/latest/"${NEXTJS_VERSION}.x"/ package.json
6565
fi
6666

67-
# Next.js v13 requires React 18.2.0
68-
if [ "$NEXTJS_VERSION" -eq "13" ]; then
69-
70-
fi
71-
7267
# Yarn install randomly started failing because it couldn't find some cache so for now we need to run these two commands which seem to fix it.
7368
# It was pretty much this issue: https://github.com/yarnpkg/yarn/issues/5275
7469
rm -rf node_modules
@@ -82,84 +77,45 @@ for NEXTJS_VERSION in 10 11 12 13; do
8277
linkcli && linkplugin
8378
mv -f package.json.bak package.json 2>/dev/null || true
8479

85-
SHOULD_RUN_WEBPACK_5=(true)
86-
# Only run Webpack 4 tests for Next 10 and Next 11
87-
if [ "$NEXTJS_VERSION" -eq "10" ] || [ "$NEXTJS_VERSION" -eq "11" ]; then
88-
SHOULD_RUN_WEBPACK_5+=(false)
89-
fi
90-
91-
for RUN_WEBPACK_5 in ${SHOULD_RUN_WEBPACK_5[*]}; do
92-
[ "$RUN_WEBPACK_5" == true ] &&
93-
WEBPACK_VERSION=5 ||
94-
WEBPACK_VERSION=4
95-
96-
if [ "$NODE_MAJOR" -gt "17" ]; then
97-
# Node v17+ does not work with NextJS 10 and 11 because of their legacy openssl use
98-
# Ref: https://github.com/vercel/next.js/issues/30078
99-
if [ "$NEXTJS_VERSION" -lt "12" ]; then
100-
echo "[nextjs@$NEXTJS_VERSION Node $NODE_MAJOR not compatible with NextJS $NEXTJS_VERSION"
101-
# Continues the 2nd enclosing loop, which is the outer loop that iterates over the NextJS version
102-
continue 2
103-
fi
104-
105-
# Node v18 only with Webpack 5 and above
106-
# https://github.com/webpack/webpack/issues/14532#issuecomment-947513562
107-
# Context: https://github.com/vercel/next.js/issues/30078#issuecomment-947338268
108-
if [ "$WEBPACK_VERSION" -eq "4" ]; then
109-
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Node $NODE_MAJOR not compatible with Webpack $WEBPACK_VERSION"
110-
# Continues the 1st enclosing loop, which is the inner loop that iterates over the Webpack version
111-
continue
112-
fi
113-
80+
if [ "$NEXTJS_VERSION" -eq "13" ]; then
81+
if [ "$USE_APPDIR" == true ]; then
82+
cat next13.appdir.config.template > next.config.js
83+
else
84+
cat next13.config.template > next.config.js
11485
fi
86+
fi
11587

116-
# next 10 defaults to webpack 4 and next 11 defaults to webpack 5, but each can use either based on settings
117-
if [ "$NEXTJS_VERSION" -eq "10" ]; then
118-
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next10.config.template >next.config.js
119-
elif [ "$NEXTJS_VERSION" -eq "11" ]; then
120-
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next11.config.template >next.config.js
121-
elif [ "$NEXTJS_VERSION" -eq "12" ]; then
122-
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next12.config.template >next.config.js
123-
elif [ "$NEXTJS_VERSION" -eq "13" ]; then
124-
if [ "$USE_APPDIR" == true ]; then
125-
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next13.appdir.config.template >next.config.js
126-
else
127-
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next13.config.template >next.config.js
128-
fi
129-
fi
88+
echo "[nextjs@$NEXTJS_VERSION] Building..."
89+
yarn build
13090

131-
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Building..."
132-
yarn build
91+
# we keep this updated as we run the tests, so that if it's ever non-zero, we can bail
92+
EXIT_CODE=0
13393

134-
# we keep this updated as we run the tests, so that if it's ever non-zero, we can bail
135-
EXIT_CODE=0
94+
if [ "$USE_APPDIR" == true ]; then
95+
echo "Skipping server tests for appdir"
96+
else
97+
echo "[nextjs@$NEXTJS_VERSION] Running server tests with options: $args"
98+
(cd .. && yarn test:integration:server) || EXIT_CODE=$?
99+
fi
136100

137-
if [ "$USE_APPDIR" == true ]; then
138-
echo "Skipping server tests for appdir"
139-
else
140-
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Running server tests with options: $args"
141-
(cd .. && yarn test:integration:server) || EXIT_CODE=$?
142-
fi
101+
if [ $EXIT_CODE -eq 0 ]; then
102+
echo "[nextjs@$NEXTJS_VERSION] Server integration tests passed"
103+
else
104+
echo "[nextjs@$NEXTJS_VERSION] Server integration tests failed"
105+
exit 1
106+
fi
143107

108+
if [ "$NODE_MAJOR" -lt "14" ]; then
109+
echo "[nextjs@$NEXTJS_VERSION] Skipping client tests on Node $NODE_MAJOR"
110+
else
111+
echo "[nextjs@$NEXTJS_VERSION] Running client tests with options: $args"
112+
(cd .. && yarn test:integration:client) || EXIT_CODE=$?
144113
if [ $EXIT_CODE -eq 0 ]; then
145-
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Server integration tests passed"
114+
echo "[nextjs@$NEXTJS_VERSION] Client integration tests passed"
146115
else
147-
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Server integration tests failed"
116+
echo "[nextjs@$NEXTJS_VERSION] Client integration tests failed"
148117
exit 1
149118
fi
150-
151-
if [ "$NODE_MAJOR" -lt "14" ]; then
152-
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Skipping client tests on Node $NODE_MAJOR"
153-
else
154-
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Running client tests with options: $args"
155-
(cd .. && yarn test:integration:client) || EXIT_CODE=$?
156-
if [ $EXIT_CODE -eq 0 ]; then
157-
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Client integration tests passed"
158-
else
159-
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Client integration tests failed"
160-
exit 1
161-
fi
162-
fi
163-
done
119+
fi
164120
done
165121
done

packages/nextjs/test/types/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"test": "ts-node test.ts"
55
},
66
"dependencies": {
7-
"next": "12.3.1"
7+
"next": "13.2.0"
88
}
99
}

packages/node-experimental/test/transports/http.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ function setupTestServer(
5353
res.connection?.end();
5454
});
5555

56-
testServer.listen(18100);
56+
testServer.listen(18101);
5757

5858
return new Promise(resolve => {
5959
testServer?.on('listening', resolve);
6060
});
6161
}
6262

63-
const TEST_SERVER_URL = 'http://localhost:18100';
63+
const TEST_SERVER_URL = 'http://localhost:18101';
6464

6565
const EVENT_ENVELOPE = createEnvelope<EventEnvelope>({ event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2', sent_at: '123' }, [
6666
[{ type: 'event' }, { event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2' }] as EventItem,

0 commit comments

Comments
 (0)