diff --git a/test/e2e/app-dir/ppr-navigations/prefetch-navigation/prefetch-navigation.test.ts b/test/e2e/app-dir/ppr-navigations/prefetch-navigation/prefetch-navigation.test.ts index 1a6368ae79b21..5524ab1e65b19 100644 --- a/test/e2e/app-dir/ppr-navigations/prefetch-navigation/prefetch-navigation.test.ts +++ b/test/e2e/app-dir/ppr-navigations/prefetch-navigation/prefetch-navigation.test.ts @@ -12,7 +12,10 @@ describe('prefetch-navigation', () => { } it('should render the prefetch without waiting for the RSC request', async () => { - const rscRequestPromise = new Map() + const rscRequestPromise = new Map< + string, + { resolve: () => Promise } + >() const browser = await next.browser('/catch-all/1', { beforePageLoad(page: Page) { page.route('**/catch-all/**', async (route: Route) => { @@ -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((res) => (resolve = res)) + let resolvePromise: () => void + const promise = new Promise((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() }