From 1c23026f323e36604f310493df5b138d942276e1 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Sun, 17 Sep 2023 10:48:19 +0200 Subject: [PATCH 1/3] Generate middlewareManifestPath only once --- packages/next/src/server/next-server.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/next/src/server/next-server.ts b/packages/next/src/server/next-server.ts index f5d3d7feb62eb..0271395ba1d13 100644 --- a/packages/next/src/server/next-server.ts +++ b/packages/next/src/server/next-server.ts @@ -145,6 +145,7 @@ function getMiddlewareMatcher( } export default class NextNodeServer extends BaseServer { + protected middlewareManifestPath: string private _serverDistDir: string | undefined private imageResponseCache?: ResponseCache protected renderWorkersPromises?: Promise @@ -231,6 +232,8 @@ export default class NextNodeServer extends BaseServer { const { interceptTestApis } = require('../experimental/testmode/server') interceptTestApis() } + + this.middlewareManifestPath = join(this.serverDistDir, MIDDLEWARE_MANIFEST) } protected async handleUpgrade(): Promise { @@ -1335,10 +1338,7 @@ export default class NextNodeServer extends BaseServer { protected getMiddlewareManifest(): MiddlewareManifest | null { if (this.minimalMode) return null - const manifest: MiddlewareManifest = require(join( - this.serverDistDir, - MIDDLEWARE_MANIFEST - )) + const manifest: MiddlewareManifest = require(this.middlewareManifestPath) return manifest } From 7ab32b62ca662519695f5828e29e7cb67db280ef Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Sun, 17 Sep 2023 11:06:09 +0200 Subject: [PATCH 2/3] Memoize getMiddlewareManifest --- packages/next/src/server/next-server.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/next/src/server/next-server.ts b/packages/next/src/server/next-server.ts index 0271395ba1d13..6fe8d0d6e23dd 100644 --- a/packages/next/src/server/next-server.ts +++ b/packages/next/src/server/next-server.ts @@ -146,6 +146,7 @@ function getMiddlewareMatcher( export default class NextNodeServer extends BaseServer { protected middlewareManifestPath: string + protected middlewareManifest: MiddlewareManifest | undefined private _serverDistDir: string | undefined private imageResponseCache?: ResponseCache protected renderWorkersPromises?: Promise @@ -1338,7 +1339,13 @@ export default class NextNodeServer extends BaseServer { protected getMiddlewareManifest(): MiddlewareManifest | null { if (this.minimalMode) return null + + if (this.middlewareManifest) { + return this.middlewareManifest + } + const manifest: MiddlewareManifest = require(this.middlewareManifestPath) + this.middlewareManifest = manifest return manifest } From fd8dc7282a0412d043ed0b5d05c2a12151e200e8 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Sun, 17 Sep 2023 11:06:49 +0200 Subject: [PATCH 3/3] Revert "Memoize getMiddlewareManifest" This reverts commit 7ab32b62ca662519695f5828e29e7cb67db280ef. --- packages/next/src/server/next-server.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/packages/next/src/server/next-server.ts b/packages/next/src/server/next-server.ts index 6fe8d0d6e23dd..0271395ba1d13 100644 --- a/packages/next/src/server/next-server.ts +++ b/packages/next/src/server/next-server.ts @@ -146,7 +146,6 @@ function getMiddlewareMatcher( export default class NextNodeServer extends BaseServer { protected middlewareManifestPath: string - protected middlewareManifest: MiddlewareManifest | undefined private _serverDistDir: string | undefined private imageResponseCache?: ResponseCache protected renderWorkersPromises?: Promise @@ -1339,13 +1338,7 @@ export default class NextNodeServer extends BaseServer { protected getMiddlewareManifest(): MiddlewareManifest | null { if (this.minimalMode) return null - - if (this.middlewareManifest) { - return this.middlewareManifest - } - const manifest: MiddlewareManifest = require(this.middlewareManifestPath) - this.middlewareManifest = manifest return manifest }