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

remove special-cased prefetch kind in dev mode #64941

Merged
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 @@ -110,12 +110,7 @@ export function getOrCreatePrefetchCacheEntry({
buildId,
nextUrl,
prefetchCache,
kind:
kind ||
// in dev, there's never gonna be a prefetch entry so we want to prefetch here
(process.env.NODE_ENV === 'development'
? PrefetchKind.AUTO
: PrefetchKind.TEMPORARY),
kind: kind || PrefetchKind.TEMPORARY,
})
}

Expand Down
119 changes: 116 additions & 3 deletions test/e2e/app-dir/app-client-cache/client-cache.experimental.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,58 @@ describe('app dir client cache semantics (experimental staleTimes)', () => {
})

if (isNextDev) {
// since the router behavior is different in development mode (no viewport prefetching + liberal revalidation)
// we only check the production behavior
it('should skip dev', () => {})
// dev doesn't support prefetch={true}, so this just performs a basic test to make sure data is fresh on each navigation
it('should trigger a loading state before fetching the page, followed by fresh data on every subsequent navigation', async () => {
const browser = await next.browser('/', browserConfigWithFixedTime)

// this test introduces an artificial delay in rendering the requested page, so we verify a loading state is rendered
await browser
.elementByCss('[href="/1?timeout=1000"]')
.click()
.waitForElementByCss('#loading')

const initialRandomNumber = await browser
.waitForElementByCss('#random-number')
.text()

await browser.elementByCss('[href="/"]').click()

await browser.eval(fastForwardTo, 5 * 1000) // fast forward 5 seconds

const newRandomNumber = await browser
.elementByCss('[href="/1?timeout=1000"]')
.click()
.waitForElementByCss('#random-number')
.text()

expect(initialRandomNumber).not.toBe(newRandomNumber)
})

describe('without a loading boundary', () => {
it('should get fresh data on every subsequent navigation', async () => {
const browser = await next.browser(
'/without-loading',
browserConfigWithFixedTime
)

const initialRandomNumber = await browser
.elementByCss('[href="/without-loading/1?timeout=1000"]')
.click()
.waitForElementByCss('#random-number')
.text()

await browser.elementByCss('[href="/without-loading"]').click()

const newRandomNumber = await browser
.elementByCss('[href="/without-loading/1?timeout=1000"]')
.click()
.waitForElementByCss('#random-number')
.text()

expect(initialRandomNumber).not.toBe(newRandomNumber)
})
})

return
}

Expand Down Expand Up @@ -308,4 +357,68 @@ describe('app dir client cache semantics (experimental staleTimes)', () => {
})
})
})

describe('dynamic: 0, static: 0', () => {
const { next } = nextTestSetup({
files: __dirname,
nextConfig: {
experimental: { staleTimes: { dynamic: 0, static: 0 } },
},
env: {
NEXT_TELEMETRY_DEBUG: '1',
},
})

// dev doesn't support prefetch={true}, so this just performs a basic test to make sure data is fresh on each navigation
it('should trigger a loading state before fetching the page, followed by fresh data on every subsequent navigation', async () => {
const browser = await next.browser('/', browserConfigWithFixedTime)

// this test introduces an artificial delay in rendering the requested page, so we verify a loading state is rendered
await browser
.elementByCss('[href="/1?timeout=1000"]')
.click()
.waitForElementByCss('#loading')

const initialRandomNumber = await browser
.waitForElementByCss('#random-number')
.text()

await browser.elementByCss('[href="/"]').click()

await browser.eval(fastForwardTo, 5 * 1000) // fast forward 5 seconds

const newRandomNumber = await browser
.elementByCss('[href="/1?timeout=1000"]')
.click()
.waitForElementByCss('#random-number')
.text()

expect(initialRandomNumber).not.toBe(newRandomNumber)
})

describe('without a loading boundary', () => {
it('should get fresh data on every subsequent navigation', async () => {
const browser = await next.browser(
'/without-loading',
browserConfigWithFixedTime
)

const initialRandomNumber = await browser
.elementByCss('[href="/without-loading/1?timeout=1000"]')
.click()
.waitForElementByCss('#random-number')
.text()

await browser.elementByCss('[href="/without-loading"]').click()

const newRandomNumber = await browser
.elementByCss('[href="/without-loading/1?timeout=1000"]')
.click()
.waitForElementByCss('#random-number')
.text()

expect(initialRandomNumber).not.toBe(newRandomNumber)
})
})
})
})
52 changes: 49 additions & 3 deletions test/e2e/app-dir/app-client-cache/client-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,55 @@ createNextDescribe(
},
({ next, isNextDev }) => {
if (isNextDev) {
// since the router behavior is different in development mode (no viewport prefetching + liberal revalidation)
// we only check the production behavior
it('should skip dev', () => {})
// dev doesn't support prefetch={true}, so this just performs a basic test to make sure data is reused for 30s
it('should renew the 30s cache once the data is revalidated', async () => {
let browser = (await next.browser(
'/',
browserConfigWithFixedTime
)) as BrowserInterface

// navigate to prefetch-auto page
await browser.elementByCss('[href="/1"]').click()

let initialNumber = await browser.elementById('random-number').text()

// Navigate back to the index, and then back to the prefetch-auto page
await browser.elementByCss('[href="/"]').click()
await browser.eval(fastForwardTo, 5 * 1000)
await browser.elementByCss('[href="/1"]').click()

let newNumber = await browser.elementById('random-number').text()

// the number should be the same, as we navigated within 30s.
expect(newNumber).toBe(initialNumber)

// Fast forward to expire the cache
await browser.eval(fastForwardTo, 30 * 1000)

// Navigate back to the index, and then back to the prefetch-auto page
await browser.elementByCss('[href="/"]').click()
await browser.elementByCss('[href="/1"]').click()

newNumber = await browser.elementById('random-number').text()

// ~35s have passed, so the cache should be expired and the number should be different
expect(newNumber).not.toBe(initialNumber)

// once the number is updated, we should have a renewed 30s cache for this entry
// store this new number so we can check that it stays the same
initialNumber = newNumber

await browser.eval(fastForwardTo, 5 * 1000)

// Navigate back to the index, and then back to the prefetch-auto page
await browser.elementByCss('[href="/"]').click()
await browser.elementByCss('[href="/1"]').click()

newNumber = await browser.elementById('random-number').text()

// the number should be the same, as we navigated within 30s (part 2).
expect(newNumber).toBe(initialNumber)
})
} else {
describe('prefetch={true}', () => {
let browser: BrowserInterface
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/app-dir/navigation/navigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,8 @@ createNextDescribe(
.click()

await retry(async () => {
// dev + PPR doesn't trigger the loading boundary as it's not prefetched
if (!(isNextDev && process.env.__NEXT_EXPERIMENTAL_PPR)) {
// dev doesn't trigger the loading boundary as it's not prefetched
if (!isNextDev) {
expect(await browser.eval(`window.shownLoading`)).toBe(true)
}

Expand Down
Loading