app-router: tweak prefetch cache status heuristics (#53864)
This PR changes the heuristic in the client cache to only check and show the prefetched data when it was prefetched or last read 30s ago vs keeping it around as long as it was accessed within 30s.
This commit is contained in:
parent
86fc1697d5
commit
6aa07fb999
2 changed files with 19 additions and 4 deletions
|
@ -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') {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue