fix(output): do not slice pathname unless ends with .txt
(#52640)
### What? When using `output: "export"`, all URL pathnames are sliced. ### Why? A regression was introduced at https://github.com/vercel/next.js/pull/50974/files#diff-7b6239af735eba0c401e1a0db1a04dd4575c19a031934f02d128cf3ac813757bR76-R80 ### How? Check if a pathname ends with `.txt` before slicing the end. Fixes #52381
This commit is contained in:
parent
6b2aed12d7
commit
539ae6c1fc
1 changed files with 8 additions and 10 deletions
|
@ -76,16 +76,14 @@ export function urlToUrlWithoutFlightMarker(url: string): URL {
|
|||
const urlWithoutFlightParameters = new URL(url, location.origin)
|
||||
urlWithoutFlightParameters.searchParams.delete(NEXT_RSC_UNION_QUERY)
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
if (process.env.__NEXT_CONFIG_OUTPUT === 'export') {
|
||||
if (urlWithoutFlightParameters.pathname.endsWith('/index.txt')) {
|
||||
// Slice off `/index.txt` from the end of the pathname
|
||||
urlWithoutFlightParameters.pathname =
|
||||
urlWithoutFlightParameters.pathname.slice(0, -`/index.txt`.length)
|
||||
} else {
|
||||
// Slice off `.txt` from the end of the pathname
|
||||
urlWithoutFlightParameters.pathname =
|
||||
urlWithoutFlightParameters.pathname.slice(0, -`.txt`.length)
|
||||
}
|
||||
if (
|
||||
process.env.__NEXT_CONFIG_OUTPUT === 'export' &&
|
||||
urlWithoutFlightParameters.pathname.endsWith('.txt')
|
||||
) {
|
||||
const { pathname } = urlWithoutFlightParameters
|
||||
const length = pathname.endsWith('/index.txt') ? 10 : 4
|
||||
// Slice off `/index.txt` or `.txt` from the end of the pathname
|
||||
urlWithoutFlightParameters.pathname = pathname.slice(0, -length)
|
||||
}
|
||||
}
|
||||
return urlWithoutFlightParameters
|
||||
|
|
Loading…
Reference in a new issue