Unverified Commit 6b89fbf1 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure asPath is correctly normalized in minimalMode with i18n (#31281)

This ensures the `asPath` and `req.url` values are normalized correctly for fallback pages with i18n in minimal mode. This also copies the minimal mode test suite to run against i18n as well. This also fixes an issue where rewrite params weren't passed correctly on the client when no params were already used in the destination. 

The provided reproduction has been deployed against this patch [here](https://nextjs-error-repro-9zdu3sp5r-ijjk-testing.vercel.app/page/test-page) show it working. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`

Fixes: https://github.com/vercel/next.js/issues/27563
Fixes: https://github.com/vercel/next.js/issues/30203
parent 6abc6699
......@@ -426,6 +426,11 @@ export default class Server {
})
try {
// ensure parsedUrl.pathname includes URL before processing
// rewrites or they won't match correctly
if (this.nextConfig.i18n && !url.locale?.path.detectedLocale) {
parsedUrl.pathname = `/${url.locale?.locale}${parsedUrl.pathname}`
}
utils.handleRewrites(req, parsedUrl)
// interpolate dynamic params and normalize URL if needed
......@@ -487,6 +492,7 @@ export default class Server {
? ''
: matchedPathname
}`
url.pathname = parsedUrl.pathname
}
addRequestMeta(req, '__nextHadTrailingSlash', url.locale?.trailingSlash)
......
......@@ -116,7 +116,6 @@ export function prepareDestination(args: {
query: NextParsedUrlQuery
}) {
const query = Object.assign({}, args.query)
const hadLocale = query.__nextLocale
delete query.__nextLocale
delete query.__nextDefaultLocale
......@@ -170,12 +169,9 @@ export function prepareDestination(args: {
// add path params to query if it's not a redirect and not
// already defined in destination query or path
let paramKeys = Object.keys(args.params)
// remove internal param for i18n
if (hadLocale) {
paramKeys = paramKeys.filter((name) => name !== 'nextInternalLocale')
}
let paramKeys = Object.keys(args.params).filter(
(name) => name !== 'nextInternalLocale'
)
if (
args.appendParamsToQuery &&
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment