Unverified Commit 0012b7d0 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Diagnose full prefetch fallback

Co-authored-by: 's avatarWill Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
parent 86625a58
......@@ -189,29 +189,11 @@ describe('searchparams-reuse-loading', () => {
setTimeout(() => resolve(), 5000)
})
const nonPrefetchRscRequests = new Set<string>()
let interceptRequests = false
let id3FullPrefetchResponse: Promise<void> | undefined
let shouldStallDynamicRequests = true
const browser = await next.browser(path, {
beforePageLoad(page) {
page.on('response', (response) => {
const requestHeaders = response.request().headers()
const url = new URL(response.url())
const normalizedPath = url.pathname.replace(/\/someValue$/, '')
const expectedPath =
path === '/' ? '/search-params' : `${path}/search-params`
if (
requestHeaders['next-router-prefetch'] &&
normalizedPath === expectedPath &&
url.searchParams.get('id') === '3' &&
response.ok()
) {
id3FullPrefetchResponse = response.finished().then((error) => {
if (error) throw error
})
}
})
page.route(
(url) => {
return url.pathname.includes('search-params')
......@@ -249,6 +231,12 @@ describe('searchparams-reuse-loading', () => {
headers['rsc'] === '1' &&
!headers['next-router-prefetch']
) {
nonPrefetchRscRequests.add(promiseKey)
if (!shouldStallDynamicRequests) {
await route.continue()
return
}
// Create a promise that will be resolved by the later test code
let resolvePromise: () => void
const promise = new Promise<void>((res) => {
......@@ -261,9 +249,13 @@ describe('searchparams-reuse-loading', () => {
rscRequestPromise.set(promiseKey, {
resolve: async () => {
const responsePromise = page.waitForResponse(
(response) => response.request() === request
)
await route.continue()
// wait a moment to ensure the response is received
await waitFor(500)
const response = await responsePromise
const error = await response.finished()
if (error) throw error
resolvePromise()
},
})
......@@ -328,25 +320,19 @@ describe('searchparams-reuse-loading', () => {
// Dev mode doesn't perform full prefetches, so this test is conditional
await browser.elementByCss(`[href='${path}']`).click()
// Wait for this specific response rather than generic network idle.
// The full prefetch can be scheduled after the page first becomes idle.
await retry(
() => expect(id3FullPrefetchResponse).toBeDefined(),
30_000,
500,
'Waiting for id=3 full prefetch response'
)
await id3FullPrefetchResponse
// A full prefetch should satisfy this navigation without a dynamic RSC
// request. Let an unexpected fallback complete so the assertion below
// reports the prefetch miss instead of hanging on an intercepted request.
shouldStallDynamicRequests = false
await browser
.elementByCss(`[href="${searchParamsPagePath}?id=3"]`)
.click()
expect(rscRequestPromise.has(`${searchParamsPagePath}?id=3`)).toBe(
false
)
// no need to resolve any dynamic requests, as this is a full prefetch
const params3 = await browser.waitForElementByCss('#params').text()
expect(params3).toBe('{"id":"3"}')
expect(nonPrefetchRscRequests.has(`${searchParamsPagePath}?id=3`)).toBe(
false
)
})
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment