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', () => { ...@@ -189,29 +189,11 @@ describe('searchparams-reuse-loading', () => {
setTimeout(() => resolve(), 5000) setTimeout(() => resolve(), 5000)
}) })
const nonPrefetchRscRequests = new Set<string>()
let interceptRequests = false let interceptRequests = false
let id3FullPrefetchResponse: Promise<void> | undefined let shouldStallDynamicRequests = true
const browser = await next.browser(path, { const browser = await next.browser(path, {
beforePageLoad(page) { 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( page.route(
(url) => { (url) => {
return url.pathname.includes('search-params') return url.pathname.includes('search-params')
...@@ -249,6 +231,12 @@ describe('searchparams-reuse-loading', () => { ...@@ -249,6 +231,12 @@ describe('searchparams-reuse-loading', () => {
headers['rsc'] === '1' && headers['rsc'] === '1' &&
!headers['next-router-prefetch'] !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 // Create a promise that will be resolved by the later test code
let resolvePromise: () => void let resolvePromise: () => void
const promise = new Promise<void>((res) => { const promise = new Promise<void>((res) => {
...@@ -261,9 +249,13 @@ describe('searchparams-reuse-loading', () => { ...@@ -261,9 +249,13 @@ describe('searchparams-reuse-loading', () => {
rscRequestPromise.set(promiseKey, { rscRequestPromise.set(promiseKey, {
resolve: async () => { resolve: async () => {
const responsePromise = page.waitForResponse(
(response) => response.request() === request
)
await route.continue() await route.continue()
// wait a moment to ensure the response is received const response = await responsePromise
await waitFor(500) const error = await response.finished()
if (error) throw error
resolvePromise() resolvePromise()
}, },
}) })
...@@ -328,25 +320,19 @@ describe('searchparams-reuse-loading', () => { ...@@ -328,25 +320,19 @@ describe('searchparams-reuse-loading', () => {
// Dev mode doesn't perform full prefetches, so this test is conditional // Dev mode doesn't perform full prefetches, so this test is conditional
await browser.elementByCss(`[href='${path}']`).click() await browser.elementByCss(`[href='${path}']`).click()
// Wait for this specific response rather than generic network idle. // A full prefetch should satisfy this navigation without a dynamic RSC
// The full prefetch can be scheduled after the page first becomes idle. // request. Let an unexpected fallback complete so the assertion below
await retry( // reports the prefetch miss instead of hanging on an intercepted request.
() => expect(id3FullPrefetchResponse).toBeDefined(), shouldStallDynamicRequests = false
30_000,
500,
'Waiting for id=3 full prefetch response'
)
await id3FullPrefetchResponse
await browser await browser
.elementByCss(`[href="${searchParamsPagePath}?id=3"]`) .elementByCss(`[href="${searchParamsPagePath}?id=3"]`)
.click() .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() const params3 = await browser.waitForElementByCss('#params').text()
expect(params3).toBe('{"id":"3"}') 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