From a2556196ea623238102662d202da32f10b3f9731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Wed, 20 Mar 2024 20:00:58 +0100 Subject: [PATCH 1/9] refactor(test): switch tests to use `pnpm` in more places (#63196) --- test/development/acceptance-app/ReactRefreshLogBox.test.ts | 2 +- test/development/acceptance/ReactRefreshLogBox.test.ts | 2 +- .../https-server.generated-key.test.ts | 2 +- .../https-server.provided-key.test.ts | 2 +- test/e2e/app-dir/next-image/next-image-https.test.ts | 2 +- test/e2e/multi-zone/multi-zone.test.ts | 2 +- test/e2e/testmode/testmode.test.ts | 4 ++-- test/integration/react-18/app/package.json | 6 +++--- test/integration/react-streaming/app/package.json | 6 +++--- .../react-streaming/unsupported-native-module/package.json | 6 +++--- .../relay-graphql-swc-multi-project/test/index.test.js | 2 +- .../relay-graphql-swc-single-project/test/index.test.js | 2 +- test/lib/e2e-utils.ts | 2 +- test/lib/next-modes/next-dev.ts | 2 +- test/lib/next-modes/next-start.ts | 4 ++-- 15 files changed, 23 insertions(+), 23 deletions(-) diff --git a/test/development/acceptance-app/ReactRefreshLogBox.test.ts b/test/development/acceptance-app/ReactRefreshLogBox.test.ts index 36461f3e9efbd..4786478abeda3 100644 --- a/test/development/acceptance-app/ReactRefreshLogBox.test.ts +++ b/test/development/acceptance-app/ReactRefreshLogBox.test.ts @@ -164,7 +164,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => { }) // TODO: investigate why this fails when running outside of the Next.js - // monorepo e.g. fails when using yarn create next-app + // monorepo e.g. fails when using pnpm create next-app // https://github.com/vercel/next.js/pull/23203 test.skip('internal package errors', async () => { const { session, cleanup } = await sandbox(next) diff --git a/test/development/acceptance/ReactRefreshLogBox.test.ts b/test/development/acceptance/ReactRefreshLogBox.test.ts index b92b4c32774b2..298bcf970701d 100644 --- a/test/development/acceptance/ReactRefreshLogBox.test.ts +++ b/test/development/acceptance/ReactRefreshLogBox.test.ts @@ -151,7 +151,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => { }) // TODO: investigate why this fails when running outside of the Next.js - // monorepo e.g. fails when using yarn create next-app + // monorepo e.g. fails when using pnpm create next-app // https://github.com/vercel/next.js/pull/23203 test.skip('internal package errors', async () => { const { session, cleanup } = await sandbox(next) diff --git a/test/development/experimental-https-server/https-server.generated-key.test.ts b/test/development/experimental-https-server/https-server.generated-key.test.ts index d4e6d94c23069..441060b52a65c 100644 --- a/test/development/experimental-https-server/https-server.generated-key.test.ts +++ b/test/development/experimental-https-server/https-server.generated-key.test.ts @@ -6,7 +6,7 @@ createNextDescribe( 'experimental-https-server (generated certificate)', { files: __dirname, - startCommand: `yarn next ${ + startCommand: `pnpm next ${ shouldRunTurboDevTest() ? 'dev --turbo' : 'dev' } --experimental-https`, skipStart: !process.env.CI, diff --git a/test/development/experimental-https-server/https-server.provided-key.test.ts b/test/development/experimental-https-server/https-server.provided-key.test.ts index aeca7dc3ae9ca..ce9312e877ad8 100644 --- a/test/development/experimental-https-server/https-server.provided-key.test.ts +++ b/test/development/experimental-https-server/https-server.provided-key.test.ts @@ -6,7 +6,7 @@ createNextDescribe( 'experimental-https-server (provided certificate)', { files: __dirname, - startCommand: `yarn next ${ + startCommand: `pnpm next ${ shouldRunTurboDevTest() ? 'dev --turbo' : 'dev' } --experimental-https --experimental-https-key ./certificates/localhost-key.pem --experimental-https-cert ./certificates/localhost.pem`, }, diff --git a/test/e2e/app-dir/next-image/next-image-https.test.ts b/test/e2e/app-dir/next-image/next-image-https.test.ts index e5e15fd75799a..2bfecedc34c69 100644 --- a/test/e2e/app-dir/next-image/next-image-https.test.ts +++ b/test/e2e/app-dir/next-image/next-image-https.test.ts @@ -5,7 +5,7 @@ createNextDescribe( { files: __dirname, skipDeployment: true, - startCommand: `yarn next dev --experimental-https`, + startCommand: `pnpm next dev --experimental-https`, }, ({ next }) => { if (!process.env.CI) { diff --git a/test/e2e/multi-zone/multi-zone.test.ts b/test/e2e/multi-zone/multi-zone.test.ts index 99b96a7929a4c..6b592bd30fa9d 100644 --- a/test/e2e/multi-zone/multi-zone.test.ts +++ b/test/e2e/multi-zone/multi-zone.test.ts @@ -12,7 +12,7 @@ createNextDescribe( packageJson: { scripts: { dev: 'node server.js', - build: 'yarn next build apps/host && yarn next build apps/guest', + build: 'next build apps/host && next build apps/guest', start: 'NODE_ENV=production node server.js', 'post-build': 'echo done', }, diff --git a/test/e2e/testmode/testmode.test.ts b/test/e2e/testmode/testmode.test.ts index caf0a948823a0..ab42e745fe2fd 100644 --- a/test/e2e/testmode/testmode.test.ts +++ b/test/e2e/testmode/testmode.test.ts @@ -8,8 +8,8 @@ createNextDescribe( skipDeployment: true, dependencies: require('./package.json').dependencies, startCommand: (global as any).isNextDev - ? 'yarn next dev --experimental-test-proxy' - : 'yarn next start --experimental-test-proxy', + ? 'pnpm next dev --experimental-test-proxy' + : 'pnpm next start --experimental-test-proxy', }, ({ next, isNextDev }) => { let proxyServer: Awaited> diff --git a/test/integration/react-18/app/package.json b/test/integration/react-18/app/package.json index 58c9b712c7ed0..7c2d78c2a3e4f 100644 --- a/test/integration/react-18/app/package.json +++ b/test/integration/react-18/app/package.json @@ -1,8 +1,8 @@ { "scripts": { - "dev": "yarn next dev", - "build": "yarn next build", - "start": "yarn next start" + "dev": "next dev", + "build": "next build", + "start": "next start" }, "dependencies": { "react": "*", diff --git a/test/integration/react-streaming/app/package.json b/test/integration/react-streaming/app/package.json index 942c2d268df9a..299559b3bd623 100644 --- a/test/integration/react-streaming/app/package.json +++ b/test/integration/react-streaming/app/package.json @@ -1,9 +1,9 @@ { "private": true, "scripts": { - "dev": "yarn next dev", - "build": "yarn next build", - "start": "yarn next start" + "dev": "next dev", + "build": "next build", + "start": "next start" }, "dependencies": { "moment": "*" diff --git a/test/integration/react-streaming/unsupported-native-module/package.json b/test/integration/react-streaming/unsupported-native-module/package.json index e34e41c75f5ab..97bbd1d711f48 100644 --- a/test/integration/react-streaming/unsupported-native-module/package.json +++ b/test/integration/react-streaming/unsupported-native-module/package.json @@ -1,8 +1,8 @@ { "private": true, "scripts": { - "dev": "yarn next dev", - "build": "yarn next build", - "start": "yarn next start" + "dev": "next dev", + "build": "next build", + "start": "next start" } } diff --git a/test/integration/relay-graphql-swc-multi-project/test/index.test.js b/test/integration/relay-graphql-swc-multi-project/test/index.test.js index 57d9907eabdce..2227b5de1b536 100644 --- a/test/integration/relay-graphql-swc-multi-project/test/index.test.js +++ b/test/integration/relay-graphql-swc-multi-project/test/index.test.js @@ -26,7 +26,7 @@ const runTests = (project) => { const runRelayCompiler = () => { // Relay expects the current directory to contain a relay.json // This ensures the CWD is the one with relay.json since running - // the relay-compiler through yarn would make the root of the repo the CWD. + // the relay-compiler through pnpm would make the root of the repo the CWD. execSync('../../../node_modules/relay-compiler/cli.js', { cwd: './test/integration/relay-graphql-swc-multi-project', }) diff --git a/test/integration/relay-graphql-swc-single-project/test/index.test.js b/test/integration/relay-graphql-swc-single-project/test/index.test.js index cabf1363fa737..2be9f79148878 100644 --- a/test/integration/relay-graphql-swc-single-project/test/index.test.js +++ b/test/integration/relay-graphql-swc-single-project/test/index.test.js @@ -24,7 +24,7 @@ const runTests = () => { const runRelayCompiler = () => { // Relay expects the current directory to contain a relay.json // This ensures the CWD is the one with relay.json since running - // the relay-compiler through yarn would make the root of the repo the CWD. + // the relay-compiler through pnpm would make the root of the repo the CWD. execSync('../../../node_modules/relay-compiler/cli.js', { cwd: './test/integration/relay-graphql-swc-single-project', }) diff --git a/test/lib/e2e-utils.ts b/test/lib/e2e-utils.ts index 209b2ba19fcb9..91149d464a727 100644 --- a/test/lib/e2e-utils.ts +++ b/test/lib/e2e-utils.ts @@ -10,7 +10,7 @@ import { shouldRunTurboDevTest } from './next-test-utils' export type { NextInstance } -// increase timeout to account for yarn install time +// increase timeout to account for pnpm install time // if either test runs for the --turbo or have a custom timeout, set reduced timeout instead. // this is due to current --turbo test have a lot of tests fails with timeouts, ends up the whole // test job exceeds the 6 hours limit. diff --git a/test/lib/next-modes/next-dev.ts b/test/lib/next-modes/next-dev.ts index 691c56e37e2f4..3d206ed8b88c8 100644 --- a/test/lib/next-modes/next-dev.ts +++ b/test/lib/next-modes/next-dev.ts @@ -29,7 +29,7 @@ export class NextDevInstance extends NextInstance { ((this as any).turbo || (this as any).experimentalTurbo) let startArgs = [ - 'yarn', + 'pnpm', 'next', useTurbo ? getTurbopackFlag() : undefined, useDirArg && this.testDir, diff --git a/test/lib/next-modes/next-start.ts b/test/lib/next-modes/next-start.ts index 6ef97ce0f4ee6..6710255b5037e 100644 --- a/test/lib/next-modes/next-start.ts +++ b/test/lib/next-modes/next-start.ts @@ -55,8 +55,8 @@ export class NextStartInstance extends NextInstance { }, } - let buildArgs = ['yarn', 'next', 'build'] - let startArgs = ['yarn', 'next', 'start'] + let buildArgs = ['pnpm', 'next', 'build'] + let startArgs = ['pnpm', 'next', 'start'] if (this.buildCommand) { buildArgs = this.buildCommand.split(' ') From f25ae9a0f97b24cde4c25c571cfc73fec088b45f Mon Sep 17 00:00:00 2001 From: Cody Olsen <81981+stipsan@users.noreply.github.com> Date: Wed, 20 Mar 2024 20:14:16 +0100 Subject: [PATCH 2/9] Update Sanity example deps (#63514) Most notably it updates `typescript` to `5.4.2` now that Sanity Studio is updated to support the [more aggressive reduction of intersections between type variables and primitive types](https://devblogs.microsoft.com/typescript/announcing-typescript-5-4/#more-aggressive-reduction-of-intersections-between-type-variables-and-primitive-types) --- examples/cms-sanity/package.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/cms-sanity/package.json b/examples/cms-sanity/package.json index 1d44773ac32d1..f519931aaeba5 100644 --- a/examples/cms-sanity/package.json +++ b/examples/cms-sanity/package.json @@ -10,30 +10,30 @@ "postsetup": "echo 'create the read token by following the rest of the guide: https://github.com/vercel/next.js/tree/canary/examples/cms-sanity#creating-a-read-token'" }, "dependencies": { - "@sanity/assist": "^2.0.3", + "@sanity/assist": "^2.0.4", "@sanity/icons": "^2.11.2", "@sanity/image-url": "^1.0.2", - "@sanity/preview-url-secret": "^1.6.4", - "@sanity/vision": "^3.33.0", + "@sanity/preview-url-secret": "^1.6.5", + "@sanity/vision": "^3.35.0", "@tailwindcss/typography": "^0.5.10", - "@types/node": "^20.11.27", - "@types/react": "^18.2.65", + "@types/node": "^20.11.30", + "@types/react": "^18.2.67", "@types/react-dom": "^18.2.22", "@vercel/speed-insights": "^1.0.10", "autoprefixer": "^10.4.18", - "date-fns": "^3.4.0", + "date-fns": "^3.6.0", "next": "latest", - "next-sanity": "^8.3.2", - "postcss": "^8.4.35", + "next-sanity": "^8.4.4", + "postcss": "^8.4.37", "react": "^18.2.0", "react-dom": "^18.2.0", "rxjs": "^7.8.1", - "sanity": "^3.33.0", + "sanity": "^3.35.0", "sanity-plugin-asset-source-unsplash": "^2.0.1", "server-only": "^0.0.1", "styled-components": "^6.1.8", "tailwindcss": "^3.4.1", - "typescript": "5.3.3" + "typescript": "5.4.2" }, "devDependencies": { "@next/env": "latest", From 00bcd55163f250ccff1964fdff7843548e2cb470 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 20 Mar 2024 13:53:39 -0700 Subject: [PATCH 3/9] Update middleware matcher docs to mention has matching (#63533) Looks like we were only documenting the `missing` matcher use case although `has` is also supported and we weren't mentioning they can combined as well. x-ref: [slack thread](https://vercel.slack.com/archives/C06LDQYNPV0/p1710704436247789) Closes NEXT-2883 --------- Co-authored-by: Zack Tanner --- .../01-routing/13-middleware.mdx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/02-app/01-building-your-application/01-routing/13-middleware.mdx b/docs/02-app/01-building-your-application/01-routing/13-middleware.mdx index 2091aec5a3e03..99e96747946c0 100644 --- a/docs/02-app/01-building-your-application/01-routing/13-middleware.mdx +++ b/docs/02-app/01-building-your-application/01-routing/13-middleware.mdx @@ -97,7 +97,7 @@ export const config = { } ``` -You can also ignore prefetches (from `next/link`) that don't need to go through the Middleware using the `missing` array: +You can also bypass Middleware for certain requests by using the `missing` or `has` arrays, or a combination of both: ```js filename="middleware.js" export const config = { @@ -116,6 +116,20 @@ export const config = { { type: 'header', key: 'purpose', value: 'prefetch' }, ], }, + + { + source: '/((?!api|_next/static|_next/image|favicon.ico).*)', + has: [ + { type: 'header', key: 'next-router-prefetch' }, + { type: 'header', key: 'purpose', value: 'prefetch' }, + ], + }, + + { + source: '/((?!api|_next/static|_next/image|favicon.ico).*)', + has: [{ type: 'header', key: 'x-present' }], + missing: [{ type: 'header', key: 'x-missing', value: 'prefetch' }], + }, ], } ``` From c0f9d246d10eb489033f12ba186777e8be1ed7a9 Mon Sep 17 00:00:00 2001 From: vercel-release-bot Date: Wed, 20 Mar 2024 23:22:37 +0000 Subject: [PATCH 4/9] v14.2.0-canary.34 --- lerna.json | 2 +- packages/create-next-app/package.json | 2 +- packages/eslint-config-next/package.json | 4 ++-- packages/eslint-plugin-next/package.json | 2 +- packages/font/package.json | 2 +- packages/next-bundle-analyzer/package.json | 2 +- packages/next-codemod/package.json | 2 +- packages/next-env/package.json | 2 +- packages/next-mdx/package.json | 2 +- packages/next-plugin-storybook/package.json | 2 +- packages/next-polyfill-module/package.json | 2 +- packages/next-polyfill-nomodule/package.json | 2 +- packages/next-swc/package.json | 2 +- packages/next/package.json | 12 ++++++------ packages/react-refresh-utils/package.json | 2 +- packages/third-parties/package.json | 4 ++-- pnpm-lock.yaml | 14 +++++++------- 17 files changed, 30 insertions(+), 30 deletions(-) diff --git a/lerna.json b/lerna.json index 13fc7c6d01926..819f9f84e9bdc 100644 --- a/lerna.json +++ b/lerna.json @@ -16,5 +16,5 @@ "registry": "https://registry.npmjs.org/" } }, - "version": "14.2.0-canary.33" + "version": "14.2.0-canary.34" } diff --git a/packages/create-next-app/package.json b/packages/create-next-app/package.json index 6e8f36210c4e3..ec121425f1946 100644 --- a/packages/create-next-app/package.json +++ b/packages/create-next-app/package.json @@ -1,6 +1,6 @@ { "name": "create-next-app", - "version": "14.2.0-canary.33", + "version": "14.2.0-canary.34", "keywords": [ "react", "next", diff --git a/packages/eslint-config-next/package.json b/packages/eslint-config-next/package.json index a8c2692fc7c55..08b6a52067656 100644 --- a/packages/eslint-config-next/package.json +++ b/packages/eslint-config-next/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-next", - "version": "14.2.0-canary.33", + "version": "14.2.0-canary.34", "description": "ESLint configuration used by Next.js.", "main": "index.js", "license": "MIT", @@ -10,7 +10,7 @@ }, "homepage": "https://nextjs.org/docs/app/building-your-application/configuring/eslint#eslint-config", "dependencies": { - "@next/eslint-plugin-next": "14.2.0-canary.33", + "@next/eslint-plugin-next": "14.2.0-canary.34", "@rushstack/eslint-patch": "^1.3.3", "@typescript-eslint/parser": "^5.4.2 || ^6.0.0 || 7.0.0 - 7.2.0", "eslint-import-resolver-node": "^0.3.6", diff --git a/packages/eslint-plugin-next/package.json b/packages/eslint-plugin-next/package.json index 112b6f5e7f963..2f3c090c51924 100644 --- a/packages/eslint-plugin-next/package.json +++ b/packages/eslint-plugin-next/package.json @@ -1,6 +1,6 @@ { "name": "@next/eslint-plugin-next", - "version": "14.2.0-canary.33", + "version": "14.2.0-canary.34", "description": "ESLint plugin for Next.js.", "main": "dist/index.js", "license": "MIT", diff --git a/packages/font/package.json b/packages/font/package.json index 7451de5a91112..e5a8cf815d738 100644 --- a/packages/font/package.json +++ b/packages/font/package.json @@ -1,6 +1,6 @@ { "name": "@next/font", - "version": "14.2.0-canary.33", + "version": "14.2.0-canary.34", "repository": { "url": "vercel/next.js", "directory": "packages/font" diff --git a/packages/next-bundle-analyzer/package.json b/packages/next-bundle-analyzer/package.json index ed15ed6235c0b..85c13ff690385 100644 --- a/packages/next-bundle-analyzer/package.json +++ b/packages/next-bundle-analyzer/package.json @@ -1,6 +1,6 @@ { "name": "@next/bundle-analyzer", - "version": "14.2.0-canary.33", + "version": "14.2.0-canary.34", "main": "index.js", "types": "index.d.ts", "license": "MIT", diff --git a/packages/next-codemod/package.json b/packages/next-codemod/package.json index 184c2fc1bcb64..c9fb3db1f1d3e 100644 --- a/packages/next-codemod/package.json +++ b/packages/next-codemod/package.json @@ -1,6 +1,6 @@ { "name": "@next/codemod", - "version": "14.2.0-canary.33", + "version": "14.2.0-canary.34", "license": "MIT", "repository": { "type": "git", diff --git a/packages/next-env/package.json b/packages/next-env/package.json index 8793bac059920..c12e2a4c58cde 100644 --- a/packages/next-env/package.json +++ b/packages/next-env/package.json @@ -1,6 +1,6 @@ { "name": "@next/env", - "version": "14.2.0-canary.33", + "version": "14.2.0-canary.34", "keywords": [ "react", "next", diff --git a/packages/next-mdx/package.json b/packages/next-mdx/package.json index a03c26ce58736..b3c0227a87847 100644 --- a/packages/next-mdx/package.json +++ b/packages/next-mdx/package.json @@ -1,6 +1,6 @@ { "name": "@next/mdx", - "version": "14.2.0-canary.33", + "version": "14.2.0-canary.34", "main": "index.js", "license": "MIT", "repository": { diff --git a/packages/next-plugin-storybook/package.json b/packages/next-plugin-storybook/package.json index f4bfcfd6f0bae..efbabe61aa2dc 100644 --- a/packages/next-plugin-storybook/package.json +++ b/packages/next-plugin-storybook/package.json @@ -1,6 +1,6 @@ { "name": "@next/plugin-storybook", - "version": "14.2.0-canary.33", + "version": "14.2.0-canary.34", "repository": { "url": "vercel/next.js", "directory": "packages/next-plugin-storybook" diff --git a/packages/next-polyfill-module/package.json b/packages/next-polyfill-module/package.json index e3dea986712e5..202721ca0f2c0 100644 --- a/packages/next-polyfill-module/package.json +++ b/packages/next-polyfill-module/package.json @@ -1,6 +1,6 @@ { "name": "@next/polyfill-module", - "version": "14.2.0-canary.33", + "version": "14.2.0-canary.34", "description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)", "main": "dist/polyfill-module.js", "license": "MIT", diff --git a/packages/next-polyfill-nomodule/package.json b/packages/next-polyfill-nomodule/package.json index 926aee4e35847..6437f8bbbc210 100644 --- a/packages/next-polyfill-nomodule/package.json +++ b/packages/next-polyfill-nomodule/package.json @@ -1,6 +1,6 @@ { "name": "@next/polyfill-nomodule", - "version": "14.2.0-canary.33", + "version": "14.2.0-canary.34", "description": "A polyfill for non-dead, nomodule browsers.", "main": "dist/polyfill-nomodule.js", "license": "MIT", diff --git a/packages/next-swc/package.json b/packages/next-swc/package.json index 3c6f7ad6a0a61..3c29bca21806f 100644 --- a/packages/next-swc/package.json +++ b/packages/next-swc/package.json @@ -1,6 +1,6 @@ { "name": "@next/swc", - "version": "14.2.0-canary.33", + "version": "14.2.0-canary.34", "private": true, "scripts": { "clean": "node ../../scripts/rm.mjs native", diff --git a/packages/next/package.json b/packages/next/package.json index 0ea4d04aeed82..f66e21ca37c4d 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -1,6 +1,6 @@ { "name": "next", - "version": "14.2.0-canary.33", + "version": "14.2.0-canary.34", "description": "The React Framework", "main": "./dist/server/next.js", "license": "MIT", @@ -92,7 +92,7 @@ ] }, "dependencies": { - "@next/env": "14.2.0-canary.33", + "@next/env": "14.2.0-canary.34", "@swc/helpers": "0.5.5", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", @@ -145,10 +145,10 @@ "@jest/types": "29.5.0", "@mswjs/interceptors": "0.23.0", "@napi-rs/triples": "1.2.0", - "@next/polyfill-module": "14.2.0-canary.33", - "@next/polyfill-nomodule": "14.2.0-canary.33", - "@next/react-refresh-utils": "14.2.0-canary.33", - "@next/swc": "14.2.0-canary.33", + "@next/polyfill-module": "14.2.0-canary.34", + "@next/polyfill-nomodule": "14.2.0-canary.34", + "@next/react-refresh-utils": "14.2.0-canary.34", + "@next/swc": "14.2.0-canary.34", "@opentelemetry/api": "1.6.0", "@playwright/test": "1.41.2", "@taskr/clear": "1.1.0", diff --git a/packages/react-refresh-utils/package.json b/packages/react-refresh-utils/package.json index d94f887d053df..9fa5e4db68956 100644 --- a/packages/react-refresh-utils/package.json +++ b/packages/react-refresh-utils/package.json @@ -1,6 +1,6 @@ { "name": "@next/react-refresh-utils", - "version": "14.2.0-canary.33", + "version": "14.2.0-canary.34", "description": "An experimental package providing utilities for React Refresh.", "repository": { "url": "vercel/next.js", diff --git a/packages/third-parties/package.json b/packages/third-parties/package.json index b5d7244780db6..3bd8f6e42a5e5 100644 --- a/packages/third-parties/package.json +++ b/packages/third-parties/package.json @@ -1,6 +1,6 @@ { "name": "@next/third-parties", - "version": "14.2.0-canary.33", + "version": "14.2.0-canary.34", "repository": { "url": "vercel/next.js", "directory": "packages/third-parties" @@ -26,7 +26,7 @@ "third-party-capital": "1.0.20" }, "devDependencies": { - "next": "14.2.0-canary.33", + "next": "14.2.0-canary.34", "outdent": "0.8.0", "prettier": "2.5.1" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ab553019ee0c3..672fc2037b347 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -747,7 +747,7 @@ importers: packages/eslint-config-next: dependencies: '@next/eslint-plugin-next': - specifier: 14.2.0-canary.33 + specifier: 14.2.0-canary.34 version: link:../eslint-plugin-next '@rushstack/eslint-patch': specifier: ^1.3.3 @@ -809,7 +809,7 @@ importers: packages/next: dependencies: '@next/env': - specifier: 14.2.0-canary.33 + specifier: 14.2.0-canary.34 version: link:../next-env '@swc/helpers': specifier: 0.5.5 @@ -930,16 +930,16 @@ importers: specifier: 1.2.0 version: 1.2.0 '@next/polyfill-module': - specifier: 14.2.0-canary.33 + specifier: 14.2.0-canary.34 version: link:../next-polyfill-module '@next/polyfill-nomodule': - specifier: 14.2.0-canary.33 + specifier: 14.2.0-canary.34 version: link:../next-polyfill-nomodule '@next/react-refresh-utils': - specifier: 14.2.0-canary.33 + specifier: 14.2.0-canary.34 version: link:../react-refresh-utils '@next/swc': - specifier: 14.2.0-canary.33 + specifier: 14.2.0-canary.34 version: link:../next-swc '@opentelemetry/api': specifier: 1.6.0 @@ -1554,7 +1554,7 @@ importers: version: 1.0.20 devDependencies: next: - specifier: 14.2.0-canary.33 + specifier: 14.2.0-canary.34 version: link:../next outdent: specifier: 0.8.0 From 8ab62613fe64c885360cb3a525ec8094529fc8cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Thu, 21 Mar 2024 01:24:33 +0100 Subject: [PATCH 5/9] chore(test): fix false-positive tests (#63242) Closes NEXT-2798 --- .../router-autoscroll/router-autoscroll.test.ts | 14 +++++++++----- .../new-link-behavior/child-a-tag-error.test.ts | 12 ++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/test/e2e/app-dir/router-autoscroll/router-autoscroll.test.ts b/test/e2e/app-dir/router-autoscroll/router-autoscroll.test.ts index a8ce936a0472e..77c7f2005e738 100644 --- a/test/e2e/app-dir/router-autoscroll/router-autoscroll.test.ts +++ b/test/e2e/app-dir/router-autoscroll/router-autoscroll.test.ts @@ -137,7 +137,7 @@ createNextDescribe( }) // Test hot reloading only in development - ;((global as any).isDev ? it : it.skip)( + ;(isNextDev ? it : it.skip)( 'should not scroll the page when we hot reload', async () => { const browser = await webdriver(next.url, '/10/10000/100/1000/page1') @@ -148,14 +148,18 @@ createNextDescribe( 'app/[layoutPaddingWidth]/[layoutPaddingHeight]/[pageWidth]/[pageHeight]/[param]/page.tsx' await browser.eval(`window.router.refresh()`) - await next.patchFile( - pagePath, - (await next.readFile(pagePath)) + + let originalContent: string + await next.patchFile(pagePath, (content) => { + originalContent = content + return ( + content + ` \\\\ Add this meaningless comment to force refresh ` - ) + ) + }) await waitForScrollToComplete(browser, { x: 0, y: 12000 }) + await next.patchFile(pagePath, originalContent) } ) }) diff --git a/test/e2e/new-link-behavior/child-a-tag-error.test.ts b/test/e2e/new-link-behavior/child-a-tag-error.test.ts index ef9824362fd85..da90b7cc5e741 100644 --- a/test/e2e/new-link-behavior/child-a-tag-error.test.ts +++ b/test/e2e/new-link-behavior/child-a-tag-error.test.ts @@ -1,5 +1,5 @@ -import { createNext, FileRef } from 'e2e-utils' -import { getRedboxSource, hasRedbox } from 'next-test-utils' +import { createNext, FileRef, isNextDev } from 'e2e-utils' +import { getRedboxDescription, hasRedbox } from 'next-test-utils' import { NextInstance } from 'test/lib/next-modes/base' import webdriver from 'next-webdriver' import path from 'path' @@ -30,13 +30,13 @@ describe('New Link Behavior with child', () => { const msg = 'Error: Invalid with child. Please remove or use ' - if ((global as any).isDev) { + if (isNextDev) { expect(next.cliOutput).toContain(msg) expect(await hasRedbox(browser)).toBe(true) - expect(await getRedboxSource(browser)).toContain(msg) - expect(link).not.toBeDefined() + expect(await getRedboxDescription(browser)).toContain(msg) + expect(link.length).toBe(0) } else { - expect(link).toBeDefined() + expect(link.length).toBeGreaterThan(0) } }) }) From aeafed9405e5e1149f5cb4e82b1b6fde3e46ac20 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Wed, 20 Mar 2024 17:36:01 -0700 Subject: [PATCH 6/9] Turbopack: Fail when module type is unhandled (#63535) This causes Turbopack to fail and communicate when a file with an unhandled or unregistered extension is built. Test Plan: `TURBOPACK=1 pnpm test-dev test/development/basic/hmr.test.ts` Closes PACK-2803 --- Cargo.lock | 70 +++++++++---------- Cargo.toml | 6 +- .../next/src/server/dev/turbopack-utils.ts | 5 +- test/development/basic/hmr.test.ts | 14 +++- 4 files changed, 54 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 82132cb223777..0ea86c0d526aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -321,7 +321,7 @@ dependencies = [ [[package]] name = "auto-hash-map" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "serde", "smallvec", @@ -3217,7 +3217,7 @@ dependencies = [ [[package]] name = "node-file-trace" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "serde", @@ -7160,7 +7160,7 @@ dependencies = [ [[package]] name = "turbo-tasks" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "async-trait", @@ -7192,7 +7192,7 @@ dependencies = [ [[package]] name = "turbo-tasks-build" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "cargo-lock", @@ -7204,7 +7204,7 @@ dependencies = [ [[package]] name = "turbo-tasks-bytes" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "bytes", @@ -7219,7 +7219,7 @@ dependencies = [ [[package]] name = "turbo-tasks-env" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "dotenvs", @@ -7233,7 +7233,7 @@ dependencies = [ [[package]] name = "turbo-tasks-fetch" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "indexmap 1.9.3", @@ -7250,7 +7250,7 @@ dependencies = [ [[package]] name = "turbo-tasks-fs" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "auto-hash-map", @@ -7282,7 +7282,7 @@ dependencies = [ [[package]] name = "turbo-tasks-hash" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "base16", "hex", @@ -7294,7 +7294,7 @@ dependencies = [ [[package]] name = "turbo-tasks-macros" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "convert_case 0.6.0", @@ -7308,7 +7308,7 @@ dependencies = [ [[package]] name = "turbo-tasks-macros-shared" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "proc-macro2", "quote", @@ -7318,7 +7318,7 @@ dependencies = [ [[package]] name = "turbo-tasks-malloc" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "mimalloc", ] @@ -7326,7 +7326,7 @@ dependencies = [ [[package]] name = "turbo-tasks-memory" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "auto-hash-map", @@ -7351,7 +7351,7 @@ dependencies = [ [[package]] name = "turbopack" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "async-recursion", @@ -7384,7 +7384,7 @@ dependencies = [ [[package]] name = "turbopack-binding" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "auto-hash-map", "mdxjs", @@ -7424,7 +7424,7 @@ dependencies = [ [[package]] name = "turbopack-browser" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "indexmap 1.9.3", @@ -7450,7 +7450,7 @@ dependencies = [ [[package]] name = "turbopack-cli-utils" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "clap", @@ -7469,7 +7469,7 @@ dependencies = [ [[package]] name = "turbopack-core" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "async-recursion", @@ -7500,7 +7500,7 @@ dependencies = [ [[package]] name = "turbopack-css" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "async-trait", @@ -7528,7 +7528,7 @@ dependencies = [ [[package]] name = "turbopack-dev-server" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "async-compression", @@ -7565,7 +7565,7 @@ dependencies = [ [[package]] name = "turbopack-ecmascript" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "async-trait", @@ -7603,7 +7603,7 @@ dependencies = [ [[package]] name = "turbopack-ecmascript-hmr-protocol" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "serde", "serde_json", @@ -7614,7 +7614,7 @@ dependencies = [ [[package]] name = "turbopack-ecmascript-plugins" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "async-trait", @@ -7639,7 +7639,7 @@ dependencies = [ [[package]] name = "turbopack-ecmascript-runtime" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "indoc", @@ -7656,7 +7656,7 @@ dependencies = [ [[package]] name = "turbopack-env" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "indexmap 1.9.3", @@ -7672,7 +7672,7 @@ dependencies = [ [[package]] name = "turbopack-image" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "base64 0.21.4", @@ -7692,7 +7692,7 @@ dependencies = [ [[package]] name = "turbopack-json" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "serde", @@ -7707,7 +7707,7 @@ dependencies = [ [[package]] name = "turbopack-mdx" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "mdxjs", @@ -7722,7 +7722,7 @@ dependencies = [ [[package]] name = "turbopack-node" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "async-stream", @@ -7760,7 +7760,7 @@ dependencies = [ [[package]] name = "turbopack-nodejs" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "indexmap 1.9.3", @@ -7784,7 +7784,7 @@ dependencies = [ [[package]] name = "turbopack-resolve" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "async-recursion", @@ -7806,7 +7806,7 @@ dependencies = [ [[package]] name = "turbopack-static" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "serde", @@ -7822,7 +7822,7 @@ dependencies = [ [[package]] name = "turbopack-swc-utils" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "swc_core", "turbo-tasks", @@ -7833,7 +7833,7 @@ dependencies = [ [[package]] name = "turbopack-trace-utils" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "crossbeam-channel", @@ -7849,7 +7849,7 @@ dependencies = [ [[package]] name = "turbopack-wasm" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240319.2#0f31686269839f10966ae1f60eb71f822f29303a" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240320.2#8a311c10a5adb45f65bf886a2f1aab1e7398d039" dependencies = [ "anyhow", "indexmap 1.9.3", diff --git a/Cargo.toml b/Cargo.toml index 15ead37c95f71..a8d661468b9f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,11 +37,11 @@ swc_core = { version = "0.90.22", features = [ testing = { version = "0.35.20" } # Turbo crates -turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240319.2" } +turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240320.2" } # [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros.. -turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240319.2" } +turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240320.2" } # [TODO]: need to refactor embed_directory! macro usage in next-core -turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240319.2" } +turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240320.2" } # General Deps diff --git a/packages/next/src/server/dev/turbopack-utils.ts b/packages/next/src/server/dev/turbopack-utils.ts index 4601778aee265..84171bc83b953 100644 --- a/packages/next/src/server/dev/turbopack-utils.ts +++ b/packages/next/src/server/dev/turbopack-utils.ts @@ -51,7 +51,10 @@ export function isWellKnownError(issue: Issue): boolean { const { title } = issue const formattedTitle = renderStyledStringToErrorAnsi(title) // TODO: add more well known errors - if (formattedTitle.includes('Module not found')) { + if ( + formattedTitle.includes('Module not found') || + formattedTitle.includes('Unknown module type') + ) { return true } diff --git a/test/development/basic/hmr.test.ts b/test/development/basic/hmr.test.ts index 7503a9670e761..e0c912099d97f 100644 --- a/test/development/basic/hmr.test.ts +++ b/test/development/basic/hmr.test.ts @@ -877,7 +877,17 @@ describe.each([[''], ['/docs']])( expect(await hasRedbox(browser)).toBe(true) expect(await getRedboxHeader(browser)).toMatch('Failed to compile') - expect(await getRedboxSource(browser)).toMatchInlineSnapshot(` + + if (process.env.TURBOPACK) { + expect(await getRedboxSource(browser)).toMatchInlineSnapshot(` + "./components/parse-error.xyz + Unknown module type + This module doesn't have an associated type. Use a known file extension, or register a loader for it. + + Read more: https://nextjs.org/docs/app/api-reference/next-config-js/turbo#webpack-loaders" + `) + } else { + expect(await getRedboxSource(browser)).toMatchInlineSnapshot(` "./components/parse-error.xyz Module parse failed: Unexpected token (3:0) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders @@ -891,7 +901,7 @@ describe.each([[''], ['/docs']])( ./components/parse-error.xyz ./pages/hmr/about8.js" `) - + } await next.patchFile(aboutPage, aboutContent) await check( From 976dd526ae991e89a3c98bbbb8fc5f57d2c575b0 Mon Sep 17 00:00:00 2001 From: OJ Kwon <1210596+kwonoj@users.noreply.github.com> Date: Wed, 20 Mar 2024 22:12:28 -0700 Subject: [PATCH 7/9] feat(custom-transform): middleware dynamic assert transform (#63538) ### What This PR implements runtime warning for dynamic codes (`eval`, `Function`...) in edge runtime. Webpack uses middleware plugin to replace / wrap codes, in case of Turbopack we don't have equivalent, so creating a new transform visitor and run it if the context is edge. Since sandbox augments global fn (__next_*), transform simply wraps the expr if it matches to the condition. Closes PACK-2804 --- packages/next-swc/crates/next-api/src/app.rs | 45 +++++++- .../next-swc/crates/next-api/src/pages.rs | 53 ++++++++- .../next-swc/crates/next-api/src/project.rs | 3 + .../next-core/src/next_server/context.rs | 9 +- .../next-core/src/next_server/transforms.rs | 7 ++ .../src/next_shared/transforms/mod.rs | 1 + .../next_middleware_dynamic_assert.rs | 37 ++++++ .../src/transforms/middleware_dynamic.rs | 105 ++++++++++++++++++ .../src/transforms/mod.rs | 1 + test/turbopack-dev-tests-manifest.json | 5 +- 10 files changed, 254 insertions(+), 12 deletions(-) create mode 100644 packages/next-swc/crates/next-core/src/next_shared/transforms/next_middleware_dynamic_assert.rs create mode 100644 packages/next-swc/crates/next-custom-transforms/src/transforms/middleware_dynamic.rs diff --git a/packages/next-swc/crates/next-api/src/app.rs b/packages/next-swc/crates/next-api/src/app.rs index 06b78ae6ebd45..2fad077fc3d07 100644 --- a/packages/next-swc/crates/next-api/src/app.rs +++ b/packages/next-swc/crates/next-api/src/app.rs @@ -177,6 +177,19 @@ impl AppProject { Value::new(self.rsc_ty()), self.project().next_mode(), self.project().next_config(), + NextRuntime::NodeJs, + )) + } + + #[turbo_tasks::function] + async fn edge_rsc_module_options_context(self: Vc) -> Result> { + Ok(get_server_module_options_context( + self.project().project_path(), + self.project().execution_context(), + Value::new(self.rsc_ty()), + self.project().next_mode(), + self.project().next_config(), + NextRuntime::Edge, )) } @@ -188,6 +201,19 @@ impl AppProject { Value::new(self.route_ty()), self.project().next_mode(), self.project().next_config(), + NextRuntime::NodeJs, + )) + } + + #[turbo_tasks::function] + async fn edge_route_module_options_context(self: Vc) -> Result> { + Ok(get_server_module_options_context( + self.project().project_path(), + self.project().execution_context(), + Value::new(self.route_ty()), + self.project().next_mode(), + self.project().next_config(), + NextRuntime::Edge, )) } @@ -292,7 +318,7 @@ impl AppProject { ModuleAssetContext::new( Vc::cell(transitions), self.project().edge_compile_time_info(), - self.rsc_module_options_context(), + self.edge_rsc_module_options_context(), self.edge_rsc_resolve_options_context(), Vc::cell("app-edge-rsc".to_string()), ) @@ -314,7 +340,7 @@ impl AppProject { ModuleAssetContext::new( Default::default(), self.project().edge_compile_time_info(), - self.route_module_options_context(), + self.edge_route_module_options_context(), self.edge_route_resolve_options_context(), Vc::cell("app-edge-route".to_string()), ) @@ -339,6 +365,19 @@ impl AppProject { Value::new(self.ssr_ty()), self.project().next_mode(), self.project().next_config(), + NextRuntime::NodeJs, + )) + } + + #[turbo_tasks::function] + async fn edge_ssr_module_options_context(self: Vc) -> Result> { + Ok(get_server_module_options_context( + self.project().project_path(), + self.project().execution_context(), + Value::new(self.ssr_ty()), + self.project().next_mode(), + self.project().next_config(), + NextRuntime::Edge, )) } @@ -378,7 +417,7 @@ impl AppProject { fn edge_ssr_transition(self: Vc) -> Vc { ContextTransition::new( self.project().edge_compile_time_info(), - self.ssr_module_options_context(), + self.edge_ssr_module_options_context(), self.edge_ssr_resolve_options_context(), Vc::cell("app-edge-ssr".to_string()), ) diff --git a/packages/next-swc/crates/next-api/src/pages.rs b/packages/next-swc/crates/next-api/src/pages.rs index b70cafad578ba..2bb866693219c 100644 --- a/packages/next-swc/crates/next-api/src/pages.rs +++ b/packages/next-swc/crates/next-api/src/pages.rs @@ -362,7 +362,7 @@ impl PagesProject { ModuleAssetContext::new( Default::default(), self.project().edge_compile_time_info(), - self.ssr_module_options_context(), + self.edge_ssr_module_options_context(), self.edge_ssr_resolve_options_context(), Vc::cell("edge-ssr".to_string()), ) @@ -373,7 +373,7 @@ impl PagesProject { ModuleAssetContext::new( Default::default(), self.project().edge_compile_time_info(), - self.api_module_options_context(), + self.edge_api_module_options_context(), self.edge_ssr_resolve_options_context(), Vc::cell("edge-api".to_string()), ) @@ -384,7 +384,7 @@ impl PagesProject { ModuleAssetContext::new( Default::default(), self.project().edge_compile_time_info(), - self.ssr_data_module_options_context(), + self.edge_ssr_data_module_options_context(), self.edge_ssr_resolve_options_context(), Vc::cell("edge-ssr-data".to_string()), ) @@ -400,6 +400,21 @@ impl PagesProject { }), self.project().next_mode(), self.project().next_config(), + NextRuntime::NodeJs, + )) + } + + #[turbo_tasks::function] + async fn edge_ssr_module_options_context(self: Vc) -> Result> { + Ok(get_server_module_options_context( + self.project().project_path(), + self.project().execution_context(), + Value::new(ServerContextType::Pages { + pages_dir: self.pages_dir(), + }), + self.project().next_mode(), + self.project().next_config(), + NextRuntime::Edge, )) } @@ -413,6 +428,21 @@ impl PagesProject { }), self.project().next_mode(), self.project().next_config(), + NextRuntime::NodeJs, + )) + } + + #[turbo_tasks::function] + async fn edge_api_module_options_context(self: Vc) -> Result> { + Ok(get_server_module_options_context( + self.project().project_path(), + self.project().execution_context(), + Value::new(ServerContextType::PagesApi { + pages_dir: self.pages_dir(), + }), + self.project().next_mode(), + self.project().next_config(), + NextRuntime::Edge, )) } @@ -426,6 +456,23 @@ impl PagesProject { }), self.project().next_mode(), self.project().next_config(), + NextRuntime::NodeJs, + )) + } + + #[turbo_tasks::function] + async fn edge_ssr_data_module_options_context( + self: Vc, + ) -> Result> { + Ok(get_server_module_options_context( + self.project().project_path(), + self.project().execution_context(), + Value::new(ServerContextType::PagesData { + pages_dir: self.pages_dir(), + }), + self.project().next_mode(), + self.project().next_config(), + NextRuntime::Edge, )) } diff --git a/packages/next-swc/crates/next-api/src/project.rs b/packages/next-swc/crates/next-api/src/project.rs index 535f783734f9f..ee0ee8333549c 100644 --- a/packages/next-swc/crates/next-api/src/project.rs +++ b/packages/next-swc/crates/next-api/src/project.rs @@ -18,6 +18,7 @@ use next_core::{ get_server_resolve_options_context, ServerContextType, }, next_telemetry::NextFeatureTelemetry, + util::NextRuntime, }; use serde::{Deserialize, Serialize}; use tracing::Instrument; @@ -809,6 +810,7 @@ impl Project { Value::new(ServerContextType::Middleware), self.next_mode(), self.next_config(), + NextRuntime::Edge, ), get_edge_resolve_options_context( self.project_path(), @@ -842,6 +844,7 @@ impl Project { Value::new(ServerContextType::Instrumentation), self.next_mode(), self.next_config(), + NextRuntime::NodeJs, ), get_server_resolve_options_context( self.project_path(), diff --git a/packages/next-swc/crates/next-core/src/next_server/context.rs b/packages/next-swc/crates/next-core/src/next_server/context.rs index 1c1bc5f00b7f8..3ef3c21f70f98 100644 --- a/packages/next-swc/crates/next-core/src/next_server/context.rs +++ b/packages/next-swc/crates/next-core/src/next_server/context.rs @@ -67,7 +67,7 @@ use crate::{ get_decorators_transform_options, get_jsx_transform_options, get_typescript_transform_options, }, - util::{foreign_code_context_condition, load_next_js_templateon}, + util::{foreign_code_context_condition, load_next_js_templateon, NextRuntime}, }; #[turbo_tasks::value(serialization = "auto_for_input")] @@ -325,11 +325,14 @@ pub async fn get_server_module_options_context( ty: Value, mode: Vc, next_config: Vc, + next_runtime: NextRuntime, ) -> Result> { let mut next_server_rules = - get_next_server_transforms_rules(next_config, ty.into_value(), mode, false).await?; + get_next_server_transforms_rules(next_config, ty.into_value(), mode, false, next_runtime) + .await?; let mut foreign_next_server_rules = - get_next_server_transforms_rules(next_config, ty.into_value(), mode, true).await?; + get_next_server_transforms_rules(next_config, ty.into_value(), mode, true, next_runtime) + .await?; let internal_custom_rules = get_next_server_internal_transforms_rules(ty.into_value(), *next_config.mdx_rs().await?) .await?; diff --git a/packages/next-swc/crates/next-core/src/next_server/transforms.rs b/packages/next-swc/crates/next-core/src/next_server/transforms.rs index 3b78af7b60691..1398f81f69ce4 100644 --- a/packages/next-swc/crates/next-core/src/next_server/transforms.rs +++ b/packages/next-swc/crates/next-core/src/next_server/transforms.rs @@ -14,8 +14,10 @@ use crate::{ get_server_actions_transform_rule, next_amp_attributes::get_next_amp_attr_rule, next_cjs_optimizer::get_next_cjs_optimizer_rule, next_disallow_re_export_all_in_page::get_next_disallow_export_all_in_page_rule, + next_middleware_dynamic_assert::get_middleware_dynamic_assert_rule, next_pure::get_next_pure_rule, server_actions::ActionsTransform, }, + util::NextRuntime, }; /// Returns a list of module rules which apply server-side, Next.js-specific @@ -25,6 +27,7 @@ pub async fn get_next_server_transforms_rules( context_ty: ServerContextType, mode: Vc, foreign_code: bool, + next_runtime: NextRuntime, ) -> Result> { let mut rules = vec![]; @@ -111,6 +114,10 @@ pub async fn get_next_server_transforms_rules( // optimize_use_state)) rules.push(get_next_image_rule()); + + if let NextRuntime::Edge = next_runtime { + rules.push(get_middleware_dynamic_assert_rule(mdx_rs)); + } } Ok(rules) diff --git a/packages/next-swc/crates/next-core/src/next_shared/transforms/mod.rs b/packages/next-swc/crates/next-core/src/next_shared/transforms/mod.rs index 2fb32d98efdd7..12812d0c04ad8 100644 --- a/packages/next-swc/crates/next-core/src/next_shared/transforms/mod.rs +++ b/packages/next-swc/crates/next-core/src/next_shared/transforms/mod.rs @@ -5,6 +5,7 @@ pub(crate) mod next_cjs_optimizer; pub(crate) mod next_disallow_re_export_all_in_page; pub(crate) mod next_dynamic; pub(crate) mod next_font; +pub(crate) mod next_middleware_dynamic_assert; pub(crate) mod next_optimize_server_react; pub(crate) mod next_page_config; pub(crate) mod next_pure; diff --git a/packages/next-swc/crates/next-core/src/next_shared/transforms/next_middleware_dynamic_assert.rs b/packages/next-swc/crates/next-core/src/next_shared/transforms/next_middleware_dynamic_assert.rs new file mode 100644 index 0000000000000..64a24c19ed435 --- /dev/null +++ b/packages/next-swc/crates/next-core/src/next_shared/transforms/next_middleware_dynamic_assert.rs @@ -0,0 +1,37 @@ +use anyhow::Result; +use async_trait::async_trait; +use next_custom_transforms::transforms::middleware_dynamic::next_middleware_dynamic; +use turbo_tasks::Vc; +use turbopack_binding::{ + swc::core::ecma::{ast::*, visit::VisitMutWith}, + turbopack::{ + ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext}, + turbopack::module_options::{ModuleRule, ModuleRuleEffect}, + }, +}; + +use super::module_rule_match_js_no_url; + +pub fn get_middleware_dynamic_assert_rule(enable_mdx_rs: bool) -> ModuleRule { + let transformer = + EcmascriptInputTransform::Plugin(Vc::cell(Box::new(NextMiddlewareDynamicAssert {}) as _)); + ModuleRule::new( + module_rule_match_js_no_url(enable_mdx_rs), + vec![ModuleRuleEffect::ExtendEcmascriptTransforms { + prepend: Vc::cell(vec![]), + append: Vc::cell(vec![transformer]), + }], + ) +} + +#[derive(Debug)] +struct NextMiddlewareDynamicAssert {} + +#[async_trait] +impl CustomTransformer for NextMiddlewareDynamicAssert { + async fn transform(&self, program: &mut Program, _ctx: &TransformContext<'_>) -> Result<()> { + let mut visitor = next_middleware_dynamic(); + program.visit_mut_with(&mut visitor); + Ok(()) + } +} diff --git a/packages/next-swc/crates/next-custom-transforms/src/transforms/middleware_dynamic.rs b/packages/next-swc/crates/next-custom-transforms/src/transforms/middleware_dynamic.rs new file mode 100644 index 0000000000000..feb70e29abf70 --- /dev/null +++ b/packages/next-swc/crates/next-custom-transforms/src/transforms/middleware_dynamic.rs @@ -0,0 +1,105 @@ +use swc_core::{ecma::visit::VisitMutWith, quote}; +use turbopack_binding::swc::core::ecma::{ast::*, visit::VisitMut}; + +enum WrappedExpr { + Eval, + WasmCompile, + WasmInstantiate, +} + +/// Replaces call / expr to dynamic evaluation in the give code to +/// wrapped expression (__next_eval__, __next_webassembly_compile__,..) to raise +/// corresponding error. +/// +/// This transform is specific to edge runtime which are not allowed to +/// call certain dynamic evaluation (eval, webassembly.instantiate, etc) +/// +/// check middleware-plugin for corresponding webpack side transform. +pub fn next_middleware_dynamic() -> MiddlewareDynamic { + MiddlewareDynamic {} +} + +pub struct MiddlewareDynamic {} + +impl VisitMut for MiddlewareDynamic { + fn visit_mut_expr(&mut self, expr: &mut Expr) { + let mut should_wrap = None; + + expr.visit_mut_children_with(self); + + if let Expr::Call(call_expr) = &expr { + let callee = &call_expr.callee; + if let Callee::Expr(callee) = callee { + // `eval('some')`, or `Function('some')` + if let Expr::Ident(ident) = &**callee { + if ident.sym == "eval" || ident.sym == "Function" { + should_wrap = Some(WrappedExpr::Eval); + } + } + + if let Expr::Member(MemberExpr { + obj, + prop: MemberProp::Ident(prop_ident), + .. + }) = &**callee + { + if let Expr::Ident(ident) = &**obj { + // `global.eval('some')` + if ident.sym == "global" && prop_ident.sym == "eval" { + should_wrap = Some(WrappedExpr::Eval); + } + + // `WebAssembly.compile('some')` & `WebAssembly.instantiate('some')` + if ident.sym == "WebAssembly" { + if prop_ident.sym == "compile" { + should_wrap = Some(WrappedExpr::WasmCompile); + } else if prop_ident.sym == "instantiate" { + should_wrap = Some(WrappedExpr::WasmInstantiate); + } + } + } + + if let Expr::Member(MemberExpr { + obj, + prop: MemberProp::Ident(member_prop_ident), + .. + }) = &**obj + { + if let Expr::Ident(ident) = &**obj { + // `global.WebAssembly.compile('some')` & + // `global.WebAssembly.instantiate('some')` + if ident.sym == "global" && member_prop_ident.sym == "WebAssembly" { + if prop_ident.sym == "compile" { + should_wrap = Some(WrappedExpr::WasmCompile); + } else if prop_ident.sym == "instantiate" { + should_wrap = Some(WrappedExpr::WasmInstantiate); + } + } + } + } + } + } + + match should_wrap { + Some(WrappedExpr::Eval) => { + *expr = quote!("__next_eval__(function() { return $orig_call });" as Expr, orig_call: Expr = Expr::Call(call_expr.clone())); + } + Some(WrappedExpr::WasmCompile) => { + *expr = quote!("__next_webassembly_compile__(function() { return $orig_call });" as Expr, orig_call: Expr = Expr::Call(call_expr.clone())); + } + Some(WrappedExpr::WasmInstantiate) => { + *expr = quote!("__next_webassembly_instantiate__(function() { return $orig_call });" as Expr, orig_call: Expr = Expr::Call(call_expr.clone())); + } + None => {} + } + } + + if let Expr::New(NewExpr { callee, .. }) = &expr { + if let Expr::Ident(ident) = &**callee { + if ident.sym == "Function" { + *expr = quote!("__next_eval__(function() { return $orig_call });" as Expr, orig_call: Expr = expr.clone()); + } + } + } + } +} diff --git a/packages/next-swc/crates/next-custom-transforms/src/transforms/mod.rs b/packages/next-swc/crates/next-custom-transforms/src/transforms/mod.rs index b35d569825461..53b4c0264af6b 100644 --- a/packages/next-swc/crates/next-custom-transforms/src/transforms/mod.rs +++ b/packages/next-swc/crates/next-custom-transforms/src/transforms/mod.rs @@ -5,6 +5,7 @@ pub mod disallow_re_export_all_in_page; pub mod dynamic; pub mod fonts; pub mod import_analyzer; +pub mod middleware_dynamic; pub mod next_ssg; pub mod optimize_server_react; pub mod page_config; diff --git a/test/turbopack-dev-tests-manifest.json b/test/turbopack-dev-tests-manifest.json index c774993e051a1..9f1d90f48cc79 100644 --- a/test/turbopack-dev-tests-manifest.json +++ b/test/turbopack-dev-tests-manifest.json @@ -9513,9 +9513,7 @@ "Edge route usage of dynamic code evaluation dev mode does not show warning when no code uses eval", "Middleware usage of dynamic code evaluation dev mode does not show a warning when running WebAssembly.instantiate with a module parameter", "Middleware usage of dynamic code evaluation dev mode does not show warning when no code uses eval", - "Page using eval in dev mode does issue dynamic code evaluation warnings" - ], - "failed": [ + "Page using eval in dev mode does issue dynamic code evaluation warnings", "Edge route usage of dynamic code evaluation dev mode shows a warning when running WebAssembly.compile", "Edge route usage of dynamic code evaluation dev mode shows a warning when running WebAssembly.instantiate with a buffer parameter", "Edge route usage of dynamic code evaluation dev mode shows a warning when running code with eval", @@ -9523,6 +9521,7 @@ "Middleware usage of dynamic code evaluation dev mode shows a warning when running WebAssembly.instantiate with a buffer parameter", "Middleware usage of dynamic code evaluation dev mode shows a warning when running code with eval" ], + "failed": [], "pending": [ "Edge route usage of dynamic code evaluation production mode should have middleware warning during build", "Middleware usage of dynamic code evaluation production mode should have middleware warning during build" From 39340ab42428606685be8bf8a01b080f385c3eb1 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Thu, 21 Mar 2024 11:05:02 +0100 Subject: [PATCH 8/9] Fix edge-can-use-wasm-files test for Turbopack (#63552) ## What? Test fix for Turbopack, the paths are slightly different. Fixes 1 test. Closes NEXT-2888 --- .../e2e/edge-can-use-wasm-files/index.test.ts | 32 +++++++++++++------ test/turbopack-dev-tests-manifest.json | 5 ++- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/test/e2e/edge-can-use-wasm-files/index.test.ts b/test/e2e/edge-can-use-wasm-files/index.test.ts index 42f8232552c23..e62df0153fb66 100644 --- a/test/e2e/edge-can-use-wasm-files/index.test.ts +++ b/test/e2e/edge-can-use-wasm-files/index.test.ts @@ -106,15 +106,29 @@ describe('middleware can use wasm files', () => { '.next/server/middleware-manifest.json' ) const manifest = await fs.readJSON(manifestPath) - expect(manifest.middleware['/']).toMatchObject({ - wasm: [ - { - filePath: - 'server/edge-chunks/wasm_58ccff8b2b94b5dac6ef8957082ecd8f6d34186d.wasm', - name: 'wasm_58ccff8b2b94b5dac6ef8957082ecd8f6d34186d', - }, - ], - }) + if (process.env.TURBOPACK) { + expect(manifest.middleware['/'].wasm).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + filePath: expect.stringMatching( + /^server\/edge\/chunks\/ssr\/.*\.wasm$/ + ), + name: expect.stringMatching(/^wasm_/), + }), + ]) + ) + } else { + expect(manifest.middleware['/'].wasm).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + filePath: expect.stringMatching( + /^server\/edge-chunks\/wasm_.*\.wasm$/ + ), + name: expect.stringMatching(/^wasm_/), + }), + ]) + ) + } }) } }) diff --git a/test/turbopack-dev-tests-manifest.json b/test/turbopack-dev-tests-manifest.json index 9f1d90f48cc79..a4a90d0c29108 100644 --- a/test/turbopack-dev-tests-manifest.json +++ b/test/turbopack-dev-tests-manifest.json @@ -5417,12 +5417,11 @@ "passed": [ "edge api endpoints can use wasm files uses the wasm file", "middleware can use wasm files can be called twice", + "middleware can use wasm files lists the necessary wasm bindings in the manifest", "middleware can use wasm files uses the wasm file", "middleware can use wasm files with the experimental modes on uses the wasm file" ], - "failed": [ - "middleware can use wasm files lists the necessary wasm bindings in the manifest" - ], + "failed": [], "pending": [], "flakey": [], "runtimeError": false From abe74a52117070e04319c8a1fe368fb39597b256 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 21 Mar 2024 09:11:03 -0400 Subject: [PATCH 9/9] fix: call instrumentationHook earlier for prod server (#63536) This ensures that the instrumentation hook for Node.js will run immediately during `next start` instead of waiting for the first request like does it `next dev`. However, if there is a separate instrumentation hook for Edge, that will still be lazy evaluated and wait until the first request. Fixes #59999 Fixes NEXT-2738 --- packages/next/src/server/next-server.ts | 10 ++++++++++ .../instrumentation-hook/instrumentation-hook.test.ts | 2 -- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/next/src/server/next-server.ts b/packages/next/src/server/next-server.ts index 90872a16cbfbe..68068bc989128 100644 --- a/packages/next/src/server/next-server.ts +++ b/packages/next/src/server/next-server.ts @@ -252,6 +252,16 @@ export default class NextNodeServer extends BaseServer { } this.middlewareManifestPath = join(this.serverDistDir, MIDDLEWARE_MANIFEST) + + // This is just optimization to fire prepare as soon as possible. It will be + // properly awaited later. We add the catch here to ensure that it does not + // cause a unhandled promise rejection. The promise rejection will be + // handled later on via the `await` when the request handler is called. + if (!options.dev) { + this.prepare().catch((err) => { + console.error('Failed to prepare server', err) + }) + } } protected async handleUpgrade(): Promise { diff --git a/test/e2e/instrumentation-hook/instrumentation-hook.test.ts b/test/e2e/instrumentation-hook/instrumentation-hook.test.ts index 011d0f8819eab..89e17b2dddb8f 100644 --- a/test/e2e/instrumentation-hook/instrumentation-hook.test.ts +++ b/test/e2e/instrumentation-hook/instrumentation-hook.test.ts @@ -67,14 +67,12 @@ describe('Instrumentation Hook', () => { describeCase('with-node-api', ({ next }) => { it('with-node-api should run the instrumentation hook', async () => { - await next.render('/api') await check(() => next.cliOutput, /instrumentation hook on nodejs/) }) }) describeCase('with-node-page', ({ next }) => { it('with-node-page should run the instrumentation hook', async () => { - await next.render('/') await check(() => next.cliOutput, /instrumentation hook on nodejs/) }) })