From bceb83582f717818e32cdaa14fc66588043fc40b Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 5 Jun 2025 20:54:33 +0200 Subject: [PATCH 1/2] refactor: patch NextServer#getMiddlewareManifest for Next >= 14 --- .../build/patch/patches/patchNextServer.ts | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/open-next/src/build/patch/patches/patchNextServer.ts b/packages/open-next/src/build/patch/patches/patchNextServer.ts index f7a87bcfd..f879b1c41 100644 --- a/packages/open-next/src/build/patch/patches/patchNextServer.ts +++ b/packages/open-next/src/build/patch/patches/patchNextServer.ts @@ -18,9 +18,9 @@ rule: inside: kind: method_definition any: - - has: {kind: property_identifier, field: name, regex: runEdgeFunction} - - has: {kind: property_identifier, field: name, regex: runMiddleware} - - has: {kind: property_identifier, field: name, regex: imageOptimizer} + - has: {kind: property_identifier, field: name, regex: ^runEdgeFunction$} + - has: {kind: property_identifier, field: name, regex: ^runMiddleware$} + - has: {kind: property_identifier, field: name, regex: ^imageOptimizer$} - has: kind: statement_block has: @@ -36,12 +36,12 @@ rule: kind: statement_block inside: kind: if_statement - any: - - has: + any: + - has: kind: member_expression pattern: this.nextConfig.experimental.preloadEntriesOnStart stopBy: end - - has: + - has: kind: binary_expression pattern: appDocumentPreloading === true stopBy: end @@ -57,7 +57,7 @@ rule: kind: method_definition has: kind: property_identifier - regex: getMiddlewareManifest + regex: ^getMiddlewareManifest$ fix: '{return null;}' `; @@ -69,7 +69,7 @@ export const patchNextServer: CodePatcher = { { versions: ">=15.0.0", field: { - pathFilter: /next-server\.(js)$/, + pathFilter: /next-server\.js$/, contentFilter: /process\.env\.NEXT_MINIMAL/, patchCode: createPatchCode(minimalRule), }, @@ -78,16 +78,15 @@ export const patchNextServer: CodePatcher = { { versions: ">=15.0.0", field: { - pathFilter: /next-server\.(js)$/, + pathFilter: /next-server\.js$/, contentFilter: /this\.nextConfig\.experimental\.preloadEntriesOnStart/, patchCode: createPatchCode(disablePreloadingRule), }, }, // Don't match edge functions in `NextServer` { - versions: ">=15.0.0", field: { - pathFilter: /next-server\.(js)$/, + pathFilter: /next-server\.js$/, contentFilter: /getMiddlewareManifest/, patchCode: createPatchCode(removeMiddlewareManifestRule), }, From 9c743c4fa2f7d1c4238e3c56c6621259a5f9af11 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 6 Jun 2025 14:42:42 +0200 Subject: [PATCH 2/2] fixup: Next >= 14 --- packages/open-next/src/build/patch/patches/patchNextServer.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/open-next/src/build/patch/patches/patchNextServer.ts b/packages/open-next/src/build/patch/patches/patchNextServer.ts index f879b1c41..05e06f3a3 100644 --- a/packages/open-next/src/build/patch/patches/patchNextServer.ts +++ b/packages/open-next/src/build/patch/patches/patchNextServer.ts @@ -85,6 +85,8 @@ export const patchNextServer: CodePatcher = { }, // Don't match edge functions in `NextServer` { + // Next 12 and some version of 13 use the bundled middleware/edge function + versions: ">=14.0.0", field: { pathFilter: /next-server\.js$/, contentFilter: /getMiddlewareManifest/,