Skip to content

Commit

Permalink
fix prefetch-navigation deploy test (#67616)
Browse files Browse the repository at this point in the history
This ensures that the route is fulfilled before resolving the promise
used in the test, to make sure we don't proceed until the network
finishes.


[x-ref](https://github.com/vercel/next.js/actions/runs/9865629712/job/27243698469)
  • Loading branch information
ztanner authored Jul 10, 2024
1 parent 4937788 commit e15549c
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ describe('prefetch-navigation', () => {
}

it('should render the prefetch without waiting for the RSC request', async () => {
const rscRequestPromise = new Map<string, any>()
const rscRequestPromise = new Map<
string,
{ resolve: () => Promise<void> }
>()
const browser = await next.browser('/catch-all/1', {
beforePageLoad(page: Page) {
page.route('**/catch-all/**', async (route: Route) => {
Expand All @@ -23,20 +26,26 @@ describe('prefetch-navigation', () => {

if (headers['rsc'] === '1' && !headers['next-router-prefetch']) {
// Create a promise that will be resolved by the later test code
let resolve: () => void
const promise = new Promise<void>((res) => (resolve = res))
let resolvePromise: () => void
const promise = new Promise<void>((res) => {
resolvePromise = res
})

if (rscRequestPromise.has(pathname)) {
throw new Error('Duplicate request')
}

rscRequestPromise.set(pathname, { route, resolve })
rscRequestPromise.set(pathname, {
resolve: async () => {
await route.continue()
// wait a moment to ensure the response is received
await new Promise((res) => setTimeout(res, 500))
resolvePromise()
},
})

// Await the promise to effectively stall the request
await promise

// Continue the route after resolving the promise
await route.continue()
} else {
await route.continue()
}
Expand Down

0 comments on commit e15549c

Please sign in to comment.