@@ -158,6 +158,10 @@ export async function fetchServerResponse(
158158 headers [ NEXT_URL ] = nextUrl
159159 }
160160
161+ // In static export mode, we need to modify the URL to request the .txt file,
162+ // but we should preserve the original URL for the canonical URL and error handling.
163+ const originalUrl = url
164+
161165 try {
162166 // When creating a "temporary" prefetch (the "on-demand" prefetch that gets created on navigation, if one doesn't exist)
163167 // we send the request with a "high" priority as it's in response to a user interaction that could be blocking a transition.
@@ -198,7 +202,7 @@ export async function fetchServerResponse(
198202 )
199203
200204 const responseUrl = urlToUrlWithoutFlightMarker ( new URL ( res . url ) )
201- const canonicalUrl = res . redirected ? responseUrl : url
205+ const canonicalUrl = res . redirected ? responseUrl : originalUrl
202206
203207 const contentType = res . headers . get ( 'content-type' ) || ''
204208 const interception = ! ! res . headers . get ( 'vary' ) ?. includes ( NEXT_URL )
@@ -285,15 +289,15 @@ export async function fetchServerResponse(
285289 } catch ( err ) {
286290 if ( ! abortController . signal . aborted ) {
287291 console . error (
288- `Failed to fetch RSC payload for ${ url } . Falling back to browser navigation.` ,
292+ `Failed to fetch RSC payload for ${ originalUrl } . Falling back to browser navigation.` ,
289293 err
290294 )
291295 }
292296
293297 // If fetch fails handle it like a mpa navigation
294298 // TODO-APP: Add a test for the case where a CORS request fails, e.g. external url redirect coming from the response.
295299 // See https://github.com/vercel/next.js/issues/43605#issuecomment-1451617521 for a reproduction.
296- return url . toString ( )
300+ return originalUrl . toString ( )
297301 }
298302}
299303
0 commit comments