From 2169e34342f06e75c06074591498544901a33206 Mon Sep 17 00:00:00 2001 From: Hendrik Liebau Date: Fri, 25 Oct 2024 20:14:23 +0200 Subject: [PATCH] Clear prefetch cache after final response is generated --- packages/next/src/server/base-server.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/next/src/server/base-server.ts b/packages/next/src/server/base-server.ts index 9281e6344c36ac..bc21d0aecc35a1 100644 --- a/packages/next/src/server/base-server.ts +++ b/packages/next/src/server/base-server.ts @@ -3103,9 +3103,15 @@ export default abstract class Server< ) } - return runWithCacheScope({ cache }, () => + const cacheEntry = runWithCacheScope({ cache }, () => originalResponseGenerator(state) ) + + // Clear the prefetch cache to ensure a clean slate for the next + // request. + this.prefetchCacheScopesDev.del(urlPathname) + + return cacheEntry } return originalResponseGenerator(state)