Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app-router: tweak prefetch cache status heuristics #53864

Merged
merged 4 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
16 changes: 14 additions & 2 deletions test/e2e/app-dir/app-client-cache/client-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand Down
Loading