From 1905d14d771b1a59090901285d69c9728deafc8e Mon Sep 17 00:00:00 2001 From: Jimmy Lai Date: Wed, 3 May 2023 19:23:15 +0200 Subject: [PATCH] app-router: fix stale cache handling (#49160) There was a bug reported in https://github.com/vercel/next.js/issues/42991#issuecomment-1532967037 that would hang on load. After investigation, I noticed that it was because the cache node never applied the flight payload. It was because the requested flight payload was too deep into the tree whereas it should have been fetched from higher up in the tree because we specifically discarded that branch of the tree because it was stale. --- .../components/router-reducer/reducers/navigate-reducer.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/next/src/client/components/router-reducer/reducers/navigate-reducer.ts b/packages/next/src/client/components/router-reducer/reducers/navigate-reducer.ts index 0c3b4c62a882d..bcd0d60bf0f9c 100644 --- a/packages/next/src/client/components/router-reducer/reducers/navigate-reducer.ts +++ b/packages/next/src/client/components/router-reducer/reducers/navigate-reducer.ts @@ -288,7 +288,8 @@ export function navigateReducer( currentCache, flightSegmentPath, treePatch, - () => fetchServerResponse(url, newTree!, state.nextUrl) + // eslint-disable-next-line no-loop-func + () => fetchServerResponse(url, currentTree, state.nextUrl) ) }