Ensure optional params are normalized correctly in minimal mode (#36513)
Follow-up for https://github.com/vercel/next.js/pull/36463 this fixes an issue with optional catch-all params not being normalized correctly which was caught by the runtimes tests. ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md`
This commit is contained in:
parent
e9b423b37c
commit
d66445f800
2 changed files with 81 additions and 1 deletions
|
@ -530,7 +530,7 @@ export default abstract class Server {
|
|||
parsedUrl.query.__nextLocale = opts.locale
|
||||
}
|
||||
} else {
|
||||
params = utils.dynamicRouteMatcher!(matchedPathnameNoExt)
|
||||
params = utils.dynamicRouteMatcher!(matchedPathnameNoExt) || {}
|
||||
}
|
||||
|
||||
if (params) {
|
||||
|
|
|
@ -804,6 +804,86 @@ describe('should set-up next', () => {
|
|||
expect(props.params).toEqual({})
|
||||
})
|
||||
|
||||
it('should normalize optional revalidations correctly for SSG page', async () => {
|
||||
const reqs = [
|
||||
{
|
||||
path: `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
|
||||
headers: {
|
||||
'x-matched-path': `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: `/_next/data/${next.buildId}/optional-ssg.json`,
|
||||
headers: {
|
||||
'x-matched-path': `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: `/_next/data/${next.buildId}/optional-ssg.json`,
|
||||
headers: {
|
||||
'x-matched-path': `/_next/data/${next.buildId}/optional-ssg.json`,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
|
||||
headers: {
|
||||
'x-matched-path': `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
|
||||
},
|
||||
query: { rest: '' },
|
||||
},
|
||||
{
|
||||
path: `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
|
||||
headers: {
|
||||
'x-matched-path': `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
|
||||
'x-now-route-matches': '1=',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: `/_next/data/${next.buildId}/optional-ssg/.json`,
|
||||
headers: {
|
||||
'x-matched-path': `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
|
||||
'x-now-route-matches': '',
|
||||
'x-vercel-id': 'cle1::',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: `/optional-ssg/[[...rest]]`,
|
||||
headers: {
|
||||
'x-matched-path': `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
|
||||
'x-now-route-matches': '',
|
||||
'x-vercel-id': 'cle1::',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
|
||||
headers: {
|
||||
'x-matched-path': `/optional-ssg/[[...rest]]`,
|
||||
'x-now-route-matches': '',
|
||||
'x-vercel-id': 'cle1::',
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
for (const req of reqs) {
|
||||
console.error('checking', req)
|
||||
const res = await fetchViaHTTP(appPort, req.path, req.query, {
|
||||
headers: req.headers,
|
||||
})
|
||||
|
||||
const content = await res.text()
|
||||
let props
|
||||
|
||||
try {
|
||||
const data = JSON.parse(content)
|
||||
props = data.pageProps
|
||||
} catch (_) {
|
||||
props = JSON.parse(cheerio.load(content)('#__NEXT_DATA__').text()).props
|
||||
.pageProps
|
||||
}
|
||||
expect(props.params).toEqual({})
|
||||
}
|
||||
})
|
||||
|
||||
it('should normalize optional values correctly for SSG page with encoded slash', async () => {
|
||||
const res = await fetchViaHTTP(
|
||||
appPort,
|
||||
|
|
Loading…
Reference in a new issue