From 7ab32b62ca662519695f5828e29e7cb67db280ef Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Sun, 17 Sep 2023 11:06:09 +0200 Subject: [PATCH] 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 }