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 35f99de505ef8..43232b9b45c4d 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 @@ -251,8 +251,11 @@ export function navigateReducer( // Unwrap cache data with `use` to suspend here (in the reducer) until the fetch resolves. const [flightData, canonicalUrlOverride] = readRecordValue(data!) - // important: we should only mark the cache node as dirty after we unsuspend from the call above - prefetchValues.lastUsedTime = Date.now() + // we only want to mark this once + if (!prefetchValues.lastUsedTime) { + // important: we should only mark the cache node as dirty after we unsuspend from the call above + prefetchValues.lastUsedTime = Date.now() + } // Handle case when navigating to page in `pages` from `app` if (typeof flightData === 'string') { diff --git a/test/e2e/app-dir/app-client-cache/client-cache.test.ts b/test/e2e/app-dir/app-client-cache/client-cache.test.ts index 4c2e451bbe37d..8d369220885d8 100644 --- a/test/e2e/app-dir/app-client-cache/client-cache.test.ts +++ b/test/e2e/app-dir/app-client-cache/client-cache.test.ts @@ -304,7 +304,7 @@ createNextDescribe( expect(number).toBe(randomNumber) - await browser.eval(fastForwardTo, 30 * 1000) + await browser.eval(fastForwardTo, 5 * 1000) await browser.elementByCss('[href="/"]').click() @@ -314,7 +314,19 @@ createNextDescribe( .waitForElementByCss('#random-number') .text() - expect(newNumber).not.toBe(randomNumber) + expect(newNumber).toBe(randomNumber) + + await browser.eval(fastForwardTo, 30 * 1000) + + await browser.elementByCss('[href="/"]').click() + + const newNumber2 = await browser + .elementByCss('[href="/1"]') + .click() + .waitForElementByCss('#random-number') + .text() + + expect(newNumber2).not.toBe(newNumber) }) it('should refetch below the fold after 30 seconds', async () => { const randomLoadingNumber = await browser