Skip to content
Open
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 @@ -240,14 +240,7 @@ export async function fetchServerResponse(
// If fetch fails handle it like a mpa navigation
// TODO-APP: Add a test for the case where a CORS request fails, e.g. external url redirect coming from the response.
// See https://github.com/vercel/next.js/issues/43605#issuecomment-1451617521 for a reproduction.
return {
flightData: url.toString(),
canonicalUrl: undefined,
couldBeIntercepted: false,
prerendered: false,
postponed: false,
staleTime: -1,
}
return doMpaNavigation(url.toString())
Copy link
Author

@azu azu Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doMpaNavigation:
https://github.com/vercel/next.js/blob/5ae7baa0e8dea2528c7b6e07d774ec729c5aa8cb/packages/next/src/client/components/router-reducer/fetch-server-response.ts#L82C1-L94C1

actual diff is just following:

-     flightData: url.toString(),
+     flightData: urlToUrlWithoutFlightMarker(url.toString()).toString(),

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,57 @@ describe('segment cache (output: "export")', () => {
}
)
})

it('fallback to HTML navigation when RSC payload fetch fails in output: "export" mode', async () => {
// This test verifies that when RSC payload fetching fails (e.g., .txt files are blocked),
// the navigation falls back to regular HTML navigation without .txt extension
let act
const browser = await webdriver(port, '/', {
beforePageLoad(p: Playwright.Page) {
act = createRouterAct(p)
// Block .txt requests at the network level to simulate RSC payload fetch failures
p.route('**/*.txt', (route) => route.abort())
},
})

// Initiate a prefetch
await act(
async () => {
const checkbox = await browser.elementByCss(
'[data-link-accordion="/target-page"]'
)
await checkbox.click()
},
{
includes: 'Target page',
}
)

// Navigate to the prefetched target page.
await act(
async () => {
const link = await browser.elementByCss('a[href="/target-page"]')
await link.click()

// Wait for navigation to complete
await browser.waitForCondition(
'document.location.pathname.includes("target-page") && document.body.textContent.includes("Target page")',
5000
)

// Verify that we navigated to the correct HTML page, not .txt
const currentUrl = await browser.url()
expect(currentUrl).not.toContain('.txt')
expect(new URL(currentUrl).pathname).toBe('/target-page')

// Verify page content is displayed
const bodyText = await browser.eval('document.body.textContent')
expect(bodyText).toContain('Target page')
},
{
// Should have prefetched the home page
includes: 'Demonstrates that per-segment prefetching works',
}
)
})
})
Loading