Unverified Commit e3e22f5b authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update search params/route params handling on deploy (#47930)

      This ensures we prefix the dynamic route params in the query so that
they can be kept separate from actual query params from the initial
request.

Fixes: https://github.com/vercel/next.js/issues/43139
  
parent 1fbbba6f
...@@ -190,7 +190,7 @@ async function generateClientSsgManifest( ...@@ -190,7 +190,7 @@ async function generateClientSsgManifest(
} }
function pageToRoute(page: string) { function pageToRoute(page: string) {
const routeRegex = getNamedRouteRegex(page) const routeRegex = getNamedRouteRegex(page, true)
return { return {
page, page,
regex: normalizeRouteRegex(routeRegex.re.source), regex: normalizeRouteRegex(routeRegex.re.source),
...@@ -1975,7 +1975,8 @@ export default async function build( ...@@ -1975,7 +1975,8 @@ export default async function build(
if (isDynamicRoute(page)) { if (isDynamicRoute(page)) {
const routeRegex = getNamedRouteRegex( const routeRegex = getNamedRouteRegex(
dataRoute.replace(/\.json$/, '') dataRoute.replace(/\.json$/, ''),
true
) )
dataRouteRegex = normalizeRouteRegex( dataRouteRegex = normalizeRouteRegex(
...@@ -2392,7 +2393,7 @@ export default async function build( ...@@ -2392,7 +2393,7 @@ export default async function build(
// dynamicParams for non-static paths? // dynamicParams for non-static paths?
finalDynamicRoutes[page] = { finalDynamicRoutes[page] = {
routeRegex: normalizeRouteRegex( routeRegex: normalizeRouteRegex(
getNamedRouteRegex(page).re.source getNamedRouteRegex(page, false).re.source
), ),
dataRoute, dataRoute,
// if dynamicParams are enabled treat as fallback: // if dynamicParams are enabled treat as fallback:
...@@ -2404,7 +2405,8 @@ export default async function build( ...@@ -2404,7 +2405,8 @@ export default async function build(
? null ? null
: normalizeRouteRegex( : normalizeRouteRegex(
getNamedRouteRegex( getNamedRouteRegex(
dataRoute.replace(/\.rsc$/, '') dataRoute.replace(/\.rsc$/, ''),
false
).re.source.replace(/\(\?:\\\/\)\?\$$/, '\\.rsc$') ).re.source.replace(/\(\?:\\\/\)\?\$$/, '\\.rsc$')
), ),
} }
...@@ -2769,7 +2771,7 @@ export default async function build( ...@@ -2769,7 +2771,7 @@ export default async function build(
finalDynamicRoutes[tbdRoute] = { finalDynamicRoutes[tbdRoute] = {
routeRegex: normalizeRouteRegex( routeRegex: normalizeRouteRegex(
getNamedRouteRegex(tbdRoute).re.source getNamedRouteRegex(tbdRoute, false).re.source
), ),
dataRoute, dataRoute,
fallback: ssgBlockingFallbackPages.has(tbdRoute) fallback: ssgBlockingFallbackPages.has(tbdRoute)
...@@ -2779,7 +2781,8 @@ export default async function build( ...@@ -2779,7 +2781,8 @@ export default async function build(
: false, : false,
dataRouteRegex: normalizeRouteRegex( dataRouteRegex: normalizeRouteRegex(
getNamedRouteRegex( getNamedRouteRegex(
dataRoute.replace(/\.json$/, '') dataRoute.replace(/\.json$/, ''),
false
).re.source.replace(/\(\?:\\\/\)\?\$$/, '\\.json$') ).re.source.replace(/\(\?:\\\/\)\?\$$/, '\\.json$')
), ),
} }
......
...@@ -59,7 +59,7 @@ async function nextMetadataImageLoader(this: any, content: Buffer) { ...@@ -59,7 +59,7 @@ async function nextMetadataImageLoader(this: any, content: Buffer) {
const exportedImageData = { ...exported } const exportedImageData = { ...exported }
export default (props) => { export default (props) => {
const pathname = ${JSON.stringify(route)} const pathname = ${JSON.stringify(route)}
const routeRegex = getNamedRouteRegex(pathname) const routeRegex = getNamedRouteRegex(pathname, false)
const route = interpolateDynamicPath(pathname, props.params, routeRegex) const route = interpolateDynamicPath(pathname, props.params, routeRegex)
const imageData = { const imageData = {
...@@ -111,7 +111,7 @@ async function nextMetadataImageLoader(this: any, content: Buffer) { ...@@ -111,7 +111,7 @@ async function nextMetadataImageLoader(this: any, content: Buffer) {
export default (props) => { export default (props) => {
const pathname = ${JSON.stringify(route)} const pathname = ${JSON.stringify(route)}
const routeRegex = getNamedRouteRegex(pathname) const routeRegex = getNamedRouteRegex(pathname, false)
const route = interpolateDynamicPath(pathname, props.params, routeRegex) const route = interpolateDynamicPath(pathname, props.params, routeRegex)
const imageData = ${JSON.stringify(imageData)}; const imageData = ${JSON.stringify(imageData)};
......
import type { ServerRuntime } from '../../types' import type { ServerRuntime } from '../../types'
export const NEXT_QUERY_PARAM_PREFIX = 'nextParam'
// in seconds // in seconds
export const CACHE_ONE_YEAR = 31536000 export const CACHE_ONE_YEAR = 31536000
......
...@@ -101,6 +101,7 @@ import { RouteKind } from './future/route-kind' ...@@ -101,6 +101,7 @@ import { RouteKind } from './future/route-kind'
import { handleInternalServerErrorResponse } from './future/route-modules/helpers/response-handlers' import { handleInternalServerErrorResponse } from './future/route-modules/helpers/response-handlers'
import { parseNextReferrerFromHeaders } from './lib/parse-next-referrer' import { parseNextReferrerFromHeaders } from './lib/parse-next-referrer'
import { fromNodeHeaders, toNodeHeaders } from './web/utils' import { fromNodeHeaders, toNodeHeaders } from './web/utils'
import { NEXT_QUERY_PARAM_PREFIX } from '../lib/constants'
export type FindComponentsResult = { export type FindComponentsResult = {
components: LoadComponentsReturnType components: LoadComponentsReturnType
...@@ -783,6 +784,24 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -783,6 +784,24 @@ export default abstract class Server<ServerOptions extends Options = Options> {
addRequestMeta(req, '_nextRewroteUrl', parsedUrl.pathname!) addRequestMeta(req, '_nextRewroteUrl', parsedUrl.pathname!)
addRequestMeta(req, '_nextDidRewrite', true) addRequestMeta(req, '_nextDidRewrite', true)
} }
const routeParamKeys = new Set<string>()
for (const key of Object.keys(parsedUrl.query)) {
const value = parsedUrl.query[key]
if (
key !== NEXT_QUERY_PARAM_PREFIX &&
key.startsWith(NEXT_QUERY_PARAM_PREFIX)
) {
const normalizedKey = key.substring(
NEXT_QUERY_PARAM_PREFIX.length
)
parsedUrl.query[normalizedKey] = value
routeParamKeys.add(normalizedKey)
delete parsedUrl.query[key]
}
}
// interpolate dynamic params and normalize URL if needed // interpolate dynamic params and normalize URL if needed
if (pageIsDynamic) { if (pageIsDynamic) {
...@@ -861,7 +880,6 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -861,7 +880,6 @@ export default abstract class Server<ServerOptions extends Options = Options> {
matchedPath = utils.interpolateDynamicPath(srcPathname, params) matchedPath = utils.interpolateDynamicPath(srcPathname, params)
req.url = utils.interpolateDynamicPath(req.url!, params) req.url = utils.interpolateDynamicPath(req.url!, params)
} }
Object.assign(parsedUrl.query, params)
} }
if (pageIsDynamic || didRewrite) { if (pageIsDynamic || didRewrite) {
...@@ -870,6 +888,9 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -870,6 +888,9 @@ export default abstract class Server<ServerOptions extends Options = Options> {
...Object.keys(utils.defaultRouteRegex?.groups || {}), ...Object.keys(utils.defaultRouteRegex?.groups || {}),
]) ])
} }
for (const key of routeParamKeys) {
delete parsedUrl.query[key]
}
parsedUrl.pathname = `${this.nextConfig.basePath || ''}${ parsedUrl.pathname = `${this.nextConfig.basePath || ''}${
matchedPath === '/' && this.nextConfig.basePath ? '' : matchedPath matchedPath === '/' && this.nextConfig.basePath ? '' : matchedPath
}` }`
......
...@@ -23,6 +23,7 @@ import { TEMPORARY_REDIRECT_STATUS } from '../shared/lib/constants' ...@@ -23,6 +23,7 @@ import { TEMPORARY_REDIRECT_STATUS } from '../shared/lib/constants'
import { addRequestMeta } from './request-meta' import { addRequestMeta } from './request-meta'
import { removeTrailingSlash } from '../shared/lib/router/utils/remove-trailing-slash' import { removeTrailingSlash } from '../shared/lib/router/utils/remove-trailing-slash'
import { normalizeRscPath } from '../shared/lib/router/utils/app-paths' import { normalizeRscPath } from '../shared/lib/router/utils/app-paths'
import { NEXT_QUERY_PARAM_PREFIX } from '../lib/constants'
export function normalizeVercelUrl( export function normalizeVercelUrl(
req: BaseNextRequest | IncomingMessage, req: BaseNextRequest | IncomingMessage,
...@@ -37,8 +38,14 @@ export function normalizeVercelUrl( ...@@ -37,8 +38,14 @@ export function normalizeVercelUrl(
const _parsedUrl = parseUrl(req.url!, true) const _parsedUrl = parseUrl(req.url!, true)
delete (_parsedUrl as any).search delete (_parsedUrl as any).search
for (const param of paramKeys || Object.keys(defaultRouteRegex.groups)) { for (const key of Object.keys(_parsedUrl.query)) {
delete _parsedUrl.query[param] if (
(key !== NEXT_QUERY_PARAM_PREFIX &&
key.startsWith(NEXT_QUERY_PARAM_PREFIX)) ||
(paramKeys || Object.keys(defaultRouteRegex.groups)).includes(key)
) {
delete _parsedUrl.query[key]
}
} }
req.url = formatUrl(_parsedUrl) req.url = formatUrl(_parsedUrl)
} }
...@@ -107,7 +114,7 @@ export function getUtils({ ...@@ -107,7 +114,7 @@ export function getUtils({
let defaultRouteMatches: ParsedUrlQuery | undefined let defaultRouteMatches: ParsedUrlQuery | undefined
if (pageIsDynamic) { if (pageIsDynamic) {
defaultRouteRegex = getNamedRouteRegex(page) defaultRouteRegex = getNamedRouteRegex(page, false)
dynamicRouteMatcher = getRouteMatcher(defaultRouteRegex) dynamicRouteMatcher = getRouteMatcher(defaultRouteRegex)
defaultRouteMatches = dynamicRouteMatcher(page) as ParsedUrlQuery defaultRouteMatches = dynamicRouteMatcher(page) as ParsedUrlQuery
} }
......
...@@ -290,7 +290,7 @@ export default class NextWebServer extends BaseServer<WebServerOptions> { ...@@ -290,7 +290,7 @@ export default class NextWebServer extends BaseServer<WebServerOptions> {
pathname = this.serverOptions.webServerConfig.page pathname = this.serverOptions.webServerConfig.page
if (isDynamicRoute(pathname)) { if (isDynamicRoute(pathname)) {
const routeRegex = getNamedRouteRegex(pathname) const routeRegex = getNamedRouteRegex(pathname, false)
pathname = interpolateDynamicPath(pathname, query, routeRegex) pathname = interpolateDynamicPath(pathname, query, routeRegex)
normalizeVercelUrl( normalizeVercelUrl(
req, req,
......
import { escapeStringRegexp } from '../../escape-regexp' import { escapeStringRegexp } from '../../escape-regexp'
import { removeTrailingSlash } from './remove-trailing-slash' import { removeTrailingSlash } from './remove-trailing-slash'
const NEXT_QUERY_PARAM_PREFIX = 'nextParam'
export interface Group { export interface Group {
pos: number pos: number
repeat: boolean repeat: boolean
...@@ -88,7 +90,7 @@ function buildGetSafeRouteKey() { ...@@ -88,7 +90,7 @@ function buildGetSafeRouteKey() {
} }
} }
function getNamedParametrizedRoute(route: string) { function getNamedParametrizedRoute(route: string, prefixRouteKeys: boolean) {
const segments = removeTrailingSlash(route).slice(1).split('/') const segments = removeTrailingSlash(route).slice(1).split('/')
const getSafeRouteKey = buildGetSafeRouteKey() const getSafeRouteKey = buildGetSafeRouteKey()
const routeKeys: { [named: string]: string } = {} const routeKeys: { [named: string]: string } = {}
...@@ -115,7 +117,13 @@ function getNamedParametrizedRoute(route: string) { ...@@ -115,7 +117,13 @@ function getNamedParametrizedRoute(route: string) {
cleanedKey = getSafeRouteKey() cleanedKey = getSafeRouteKey()
} }
routeKeys[cleanedKey] = key if (prefixRouteKeys) {
cleanedKey = `${NEXT_QUERY_PARAM_PREFIX}${cleanedKey}`
routeKeys[cleanedKey] = `${NEXT_QUERY_PARAM_PREFIX}${key}`
} else {
routeKeys[cleanedKey] = `${key}`
}
return repeat return repeat
? optional ? optional
? `(?:/(?<${cleanedKey}>.+?))?` ? `(?:/(?<${cleanedKey}>.+?))?`
...@@ -133,10 +141,16 @@ function getNamedParametrizedRoute(route: string) { ...@@ -133,10 +141,16 @@ function getNamedParametrizedRoute(route: string) {
/** /**
* This function extends `getRouteRegex` generating also a named regexp where * This function extends `getRouteRegex` generating also a named regexp where
* each group is named along with a routeKeys object that indexes the assigned * each group is named along with a routeKeys object that indexes the assigned
* named group with its corresponding key. * named group with its corresponding key. When the routeKeys need to be
* prefixed to uniquely identify internally the "prefixRouteKey" arg should
* be "true" currently this is only the case when creating the routes-manifest
* during the build
*/ */
export function getNamedRouteRegex(normalizedRoute: string) { export function getNamedRouteRegex(
const result = getNamedParametrizedRoute(normalizedRoute) normalizedRoute: string,
prefixRouteKey: boolean
) {
const result = getNamedParametrizedRoute(normalizedRoute, prefixRouteKey)
return { return {
...getRouteRegex(normalizedRoute), ...getRouteRegex(normalizedRoute),
namedRegex: `^${result.namedParameterizedRoute}(?:/)?$`, namedRegex: `^${result.namedParameterizedRoute}(?:/)?$`,
...@@ -163,7 +177,10 @@ export function getNamedMiddlewareRegex( ...@@ -163,7 +177,10 @@ export function getNamedMiddlewareRegex(
} }
} }
const { namedParameterizedRoute } = getNamedParametrizedRoute(normalizedRoute) const { namedParameterizedRoute } = getNamedParametrizedRoute(
normalizedRoute,
false
)
let catchAllGroupedRegex = catchAll ? '(?:(/.*)?)' : '' let catchAllGroupedRegex = catchAll ? '(?:(/.*)?)' : ''
return { return {
namedRegex: `^${namedParameterizedRoute}${catchAllGroupedRegex}$`, namedRegex: `^${namedParameterizedRoute}${catchAllGroupedRegex}$`,
......
'use client' 'use client'
import { useSearchParams } from 'next/navigation'
export default function IdPage({ children, params }) { export default function IdPage({ children, params }) {
return ( return (
<> <>
...@@ -8,6 +10,10 @@ export default function IdPage({ children, params }) { ...@@ -8,6 +10,10 @@ export default function IdPage({ children, params }) {
<span id="id-page-params">{JSON.stringify(params)}</span> <span id="id-page-params">{JSON.stringify(params)}</span>
</p> </p>
{children} {children}
<p id="search-params">
{JSON.stringify(Object.fromEntries(useSearchParams()))}
</p>
</> </>
) )
} }
export default function IdPage({ children, params }) { export default function IdPage({ children, params, searchParams }) {
return ( return (
<> <>
<p> <p>
...@@ -6,6 +6,8 @@ export default function IdPage({ children, params }) { ...@@ -6,6 +6,8 @@ export default function IdPage({ children, params }) {
<span id="id-page-params">{JSON.stringify(params)}</span> <span id="id-page-params">{JSON.stringify(params)}</span>
</p> </p>
{children} {children}
<p id="search-params">{JSON.stringify(searchParams)}</p>
</> </>
) )
} }
...@@ -10,6 +10,35 @@ createNextDescribe( ...@@ -10,6 +10,35 @@ createNextDescribe(
files: __dirname, files: __dirname,
}, },
({ next, isNextDev: isDev, isNextStart, isNextDeploy }) => { ({ next, isNextDev: isDev, isNextStart, isNextDeploy }) => {
it('should have correct searchParams and params (server)', async () => {
const html = await next.render('/dynamic/category-1/id-2?query1=value2')
const $ = cheerio.load(html)
expect(JSON.parse($('#id-page-params').text())).toEqual({
category: 'category-1',
id: 'id-2',
})
expect(JSON.parse($('#search-params').text())).toEqual({
query1: 'value2',
})
})
it('should have correct searchParams and params (client)', async () => {
const browser = await next.browser(
'/dynamic-client/category-1/id-2?query1=value2'
)
const html = await browser.eval('document.documentElement.innerHTML')
const $ = cheerio.load(html)
expect(JSON.parse($('#id-page-params').text())).toEqual({
category: 'category-1',
id: 'id-2',
})
expect(JSON.parse($('#search-params').text())).toEqual({
query1: 'value2',
})
})
if (!isDev) { if (!isDev) {
it('should successfully detect app route during prefetch', async () => { it('should successfully detect app route during prefetch', async () => {
const browser = await next.browser('/') const browser = await next.browser('/')
......
...@@ -5,6 +5,8 @@ createNextDescribe( ...@@ -5,6 +5,8 @@ createNextDescribe(
'parallel-routes-and-interception', 'parallel-routes-and-interception',
{ {
files: __dirname, files: __dirname,
// TODO: remove after deployment handling is updated
skipDeployment: true,
}, },
({ next }) => { ({ next }) => {
describe('parallel routes', () => { describe('parallel routes', () => {
......
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
...@@ -140,10 +140,10 @@ describe('edge-render-getserversideprops', () => { ...@@ -140,10 +140,10 @@ describe('edge-render-getserversideprops', () => {
), ),
namedDataRouteRegex: `^/_next/data/${escapeStringRegexp( namedDataRouteRegex: `^/_next/data/${escapeStringRegexp(
next.buildId next.buildId
)}/(?<id>[^/]+?)\\.json$`, )}/(?<nextParamid>[^/]+?)\\.json$`,
page: '/[id]', page: '/[id]',
routeKeys: { routeKeys: {
id: 'id', nextParamid: 'nextParamid',
}, },
}, },
]) ])
......
...@@ -43,19 +43,19 @@ const expectedManifestRoutes = () => [ ...@@ -43,19 +43,19 @@ const expectedManifestRoutes = () => [
{ {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId buildId
)}/blog/(?<post>[^/]+?)\\.json$`, )}/blog/(?<nextParampost>[^/]+?)\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/blog\\/([^\\/]+?)\\.json$` `^\\/_next\\/data\\/${escapeRegex(buildId)}\\/blog\\/([^\\/]+?)\\.json$`
), ),
page: '/blog/[post]', page: '/blog/[post]',
routeKeys: { routeKeys: {
post: 'post', nextParampost: 'nextParampost',
}, },
}, },
{ {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId buildId
)}/blog/(?<post>[^/]+?)/(?<comment>[^/]+?)\\.json$`, )}/blog/(?<nextParampost>[^/]+?)/(?<nextParamcomment>[^/]+?)\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex( `^\\/_next\\/data\\/${escapeRegex(
buildId buildId
...@@ -63,20 +63,20 @@ const expectedManifestRoutes = () => [ ...@@ -63,20 +63,20 @@ const expectedManifestRoutes = () => [
), ),
page: '/blog/[post]/[comment]', page: '/blog/[post]/[comment]',
routeKeys: { routeKeys: {
post: 'post', nextParampost: 'nextParampost',
comment: 'comment', nextParamcomment: 'nextParamcomment',
}, },
}, },
{ {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId buildId
)}/catchall/(?<path>.+?)\\.json$`, )}/catchall/(?<nextParampath>.+?)\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/catchall\\/(.+?)\\.json$` `^\\/_next\\/data\\/${escapeRegex(buildId)}\\/catchall\\/(.+?)\\.json$`
), ),
page: '/catchall/[...path]', page: '/catchall/[...path]',
routeKeys: { routeKeys: {
path: 'path', nextParampath: 'nextParampath',
}, },
}, },
{ {
...@@ -127,10 +127,10 @@ const expectedManifestRoutes = () => [ ...@@ -127,10 +127,10 @@ const expectedManifestRoutes = () => [
)}\\/not\\-found\\/([^\\/]+?)\\.json$`, )}\\/not\\-found\\/([^\\/]+?)\\.json$`,
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId buildId
)}/not\\-found/(?<slug>[^/]+?)\\.json$`, )}/not\\-found/(?<nextParamslug>[^/]+?)\\.json$`,
page: '/not-found/[slug]', page: '/not-found/[slug]',
routeKeys: { routeKeys: {
slug: 'slug', nextParamslug: 'nextParamslug',
}, },
}, },
{ {
...@@ -182,7 +182,7 @@ const expectedManifestRoutes = () => [ ...@@ -182,7 +182,7 @@ const expectedManifestRoutes = () => [
{ {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId buildId
)}/user/(?<user>[^/]+?)/profile\\.json$`, )}/user/(?<nextParamuser>[^/]+?)/profile\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex( `^\\/_next\\/data\\/${escapeRegex(
buildId buildId
...@@ -190,7 +190,7 @@ const expectedManifestRoutes = () => [ ...@@ -190,7 +190,7 @@ const expectedManifestRoutes = () => [
), ),
page: '/user/[user]/profile', page: '/user/[user]/profile',
routeKeys: { routeKeys: {
user: 'user', nextParamuser: 'nextParamuser',
}, },
}, },
] ]
......
...@@ -1316,10 +1316,10 @@ describe('Prerender', () => { ...@@ -1316,10 +1316,10 @@ describe('Prerender', () => {
), ),
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId next.buildId
)}/api\\-docs/(?<slug>.+?)\\.json$`, )}/api\\-docs/(?<nextParamslug>.+?)\\.json$`,
page: '/api-docs/[...slug]', page: '/api-docs/[...slug]',
routeKeys: { routeKeys: {
slug: 'slug', nextParamslug: 'nextParamslug',
}, },
}, },
{ {
...@@ -1346,9 +1346,9 @@ describe('Prerender', () => { ...@@ -1346,9 +1346,9 @@ describe('Prerender', () => {
), ),
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId next.buildId
)}/blocking\\-fallback/(?<slug>[^/]+?)\\.json$`, )}/blocking\\-fallback/(?<nextParamslug>[^/]+?)\\.json$`,
page: '/blocking-fallback/[slug]', page: '/blocking-fallback/[slug]',
routeKeys: { slug: 'slug' }, routeKeys: { nextParamslug: 'nextParamslug' },
}, },
{ {
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
...@@ -1358,9 +1358,9 @@ describe('Prerender', () => { ...@@ -1358,9 +1358,9 @@ describe('Prerender', () => {
), ),
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId next.buildId
)}/blocking\\-fallback\\-once/(?<slug>[^/]+?)\\.json$`, )}/blocking\\-fallback\\-once/(?<nextParamslug>[^/]+?)\\.json$`,
page: '/blocking-fallback-once/[slug]', page: '/blocking-fallback-once/[slug]',
routeKeys: { slug: 'slug' }, routeKeys: { nextParamslug: 'nextParamslug' },
}, },
{ {
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
...@@ -1370,9 +1370,9 @@ describe('Prerender', () => { ...@@ -1370,9 +1370,9 @@ describe('Prerender', () => {
), ),
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId next.buildId
)}/blocking\\-fallback\\-some/(?<slug>[^/]+?)\\.json$`, )}/blocking\\-fallback\\-some/(?<nextParamslug>[^/]+?)\\.json$`,
page: '/blocking-fallback-some/[slug]', page: '/blocking-fallback-some/[slug]',
routeKeys: { slug: 'slug' }, routeKeys: { nextParamslug: 'nextParamslug' },
}, },
{ {
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
...@@ -1383,7 +1383,7 @@ describe('Prerender', () => { ...@@ -1383,7 +1383,7 @@ describe('Prerender', () => {
{ {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId next.buildId
)}/blog/(?<post>[^/]+?)\\.json$`, )}/blog/(?<nextParampost>[^/]+?)\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex( `^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
...@@ -1391,13 +1391,13 @@ describe('Prerender', () => { ...@@ -1391,13 +1391,13 @@ describe('Prerender', () => {
), ),
page: '/blog/[post]', page: '/blog/[post]',
routeKeys: { routeKeys: {
post: 'post', nextParampost: 'nextParampost',
}, },
}, },
{ {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId next.buildId
)}/blog/(?<post>[^/]+?)/(?<comment>[^/]+?)\\.json$`, )}/blog/(?<nextParampost>[^/]+?)/(?<nextParamcomment>[^/]+?)\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex( `^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
...@@ -1405,14 +1405,14 @@ describe('Prerender', () => { ...@@ -1405,14 +1405,14 @@ describe('Prerender', () => {
), ),
page: '/blog/[post]/[comment]', page: '/blog/[post]/[comment]',
routeKeys: { routeKeys: {
post: 'post', nextParampost: 'nextParampost',
comment: 'comment', nextParamcomment: 'nextParamcomment',
}, },
}, },
{ {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId next.buildId
)}/catchall/(?<slug>.+?)\\.json$`, )}/catchall/(?<nextParamslug>.+?)\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex( `^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
...@@ -1420,13 +1420,13 @@ describe('Prerender', () => { ...@@ -1420,13 +1420,13 @@ describe('Prerender', () => {
), ),
page: '/catchall/[...slug]', page: '/catchall/[...slug]',
routeKeys: { routeKeys: {
slug: 'slug', nextParamslug: 'nextParamslug',
}, },
}, },
{ {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId next.buildId
)}/catchall\\-explicit/(?<slug>.+?)\\.json$`, )}/catchall\\-explicit/(?<nextParamslug>.+?)\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex( `^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
...@@ -1434,13 +1434,13 @@ describe('Prerender', () => { ...@@ -1434,13 +1434,13 @@ describe('Prerender', () => {
), ),
page: '/catchall-explicit/[...slug]', page: '/catchall-explicit/[...slug]',
routeKeys: { routeKeys: {
slug: 'slug', nextParamslug: 'nextParamslug',
}, },
}, },
{ {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId next.buildId
)}/catchall\\-optional(?:/(?<slug>.+?))?\\.json$`, )}/catchall\\-optional(?:/(?<nextParamslug>.+?))?\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex( `^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
...@@ -1448,7 +1448,7 @@ describe('Prerender', () => { ...@@ -1448,7 +1448,7 @@ describe('Prerender', () => {
), ),
page: '/catchall-optional/[[...slug]]', page: '/catchall-optional/[[...slug]]',
routeKeys: { routeKeys: {
slug: 'slug', nextParamslug: 'nextParamslug',
}, },
}, },
{ {
...@@ -1467,10 +1467,10 @@ describe('Prerender', () => { ...@@ -1467,10 +1467,10 @@ describe('Prerender', () => {
), ),
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId next.buildId
)}/dynamic/(?<slug>[^/]+?)\\.json$`, )}/dynamic/(?<nextParamslug>[^/]+?)\\.json$`,
page: '/dynamic/[slug]', page: '/dynamic/[slug]',
routeKeys: { routeKeys: {
slug: 'slug', nextParamslug: 'nextParamslug',
}, },
}, },
{ {
...@@ -1481,10 +1481,10 @@ describe('Prerender', () => { ...@@ -1481,10 +1481,10 @@ describe('Prerender', () => {
), ),
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId next.buildId
)}/fallback\\-only/(?<slug>[^/]+?)\\.json$`, )}/fallback\\-only/(?<nextParamslug>[^/]+?)\\.json$`,
page: '/fallback-only/[slug]', page: '/fallback-only/[slug]',
routeKeys: { routeKeys: {
slug: 'slug', nextParamslug: 'nextParamslug',
}, },
}, },
// TODO: investigate index/index // TODO: investigate index/index
...@@ -1499,7 +1499,7 @@ describe('Prerender', () => { ...@@ -1499,7 +1499,7 @@ describe('Prerender', () => {
{ {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId next.buildId
)}/lang/(?<lang>[^/]+?)/about\\.json$`, )}/lang/(?<nextParamlang>[^/]+?)/about\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex( `^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
...@@ -1507,7 +1507,7 @@ describe('Prerender', () => { ...@@ -1507,7 +1507,7 @@ describe('Prerender', () => {
), ),
page: '/lang/[lang]/about', page: '/lang/[lang]/about',
routeKeys: { routeKeys: {
lang: 'lang', nextParamlang: 'nextParamlang',
}, },
}, },
{ {
...@@ -1525,7 +1525,7 @@ describe('Prerender', () => { ...@@ -1525,7 +1525,7 @@ describe('Prerender', () => {
{ {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId next.buildId
)}/non\\-json/(?<p>[^/]+?)\\.json$`, )}/non\\-json/(?<nextParamp>[^/]+?)\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex( `^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
...@@ -1533,13 +1533,13 @@ describe('Prerender', () => { ...@@ -1533,13 +1533,13 @@ describe('Prerender', () => {
), ),
page: '/non-json/[p]', page: '/non-json/[p]',
routeKeys: { routeKeys: {
p: 'p', nextParamp: 'nextParamp',
}, },
}, },
{ {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId next.buildId
)}/non\\-json\\-blocking/(?<p>[^/]+?)\\.json$`, )}/non\\-json\\-blocking/(?<nextParamp>[^/]+?)\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex( `^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
...@@ -1547,7 +1547,7 @@ describe('Prerender', () => { ...@@ -1547,7 +1547,7 @@ describe('Prerender', () => {
), ),
page: '/non-json-blocking/[p]', page: '/non-json-blocking/[p]',
routeKeys: { routeKeys: {
p: 'p', nextParamp: 'nextParamp',
}, },
}, },
{ {
...@@ -1575,7 +1575,7 @@ describe('Prerender', () => { ...@@ -1575,7 +1575,7 @@ describe('Prerender', () => {
{ {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId next.buildId
)}/user/(?<user>[^/]+?)/profile\\.json$`, )}/user/(?<nextParamuser>[^/]+?)/profile\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex( `^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
...@@ -1583,7 +1583,7 @@ describe('Prerender', () => { ...@@ -1583,7 +1583,7 @@ describe('Prerender', () => {
), ),
page: '/user/[user]/profile', page: '/user/[user]/profile',
routeKeys: { routeKeys: {
user: 'user', nextParamuser: 'nextParamuser',
}, },
}, },
]) ])
......
...@@ -1544,10 +1544,10 @@ const runTests = (isDev = false, isTurbo = false) => { ...@@ -1544,10 +1544,10 @@ const runTests = (isDev = false, isTurbo = false) => {
), ),
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId buildId
)}/blog\\-catchall/(?<slug>.+?)\\.json$`, )}/blog\\-catchall/(?<nextParamslug>.+?)\\.json$`,
page: '/blog-catchall/[...slug]', page: '/blog-catchall/[...slug]',
routeKeys: { routeKeys: {
slug: 'slug', nextParamslug: 'nextParamslug',
}, },
}, },
{ {
...@@ -1556,10 +1556,10 @@ const runTests = (isDev = false, isTurbo = false) => { ...@@ -1556,10 +1556,10 @@ const runTests = (isDev = false, isTurbo = false) => {
)}\\/overridden\\/([^\\/]+?)\\.json$`, )}\\/overridden\\/([^\\/]+?)\\.json$`,
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId buildId
)}/overridden/(?<slug>[^/]+?)\\.json$`, )}/overridden/(?<nextParamslug>[^/]+?)\\.json$`,
page: '/overridden/[slug]', page: '/overridden/[slug]',
routeKeys: { routeKeys: {
slug: 'slug', nextParamslug: 'nextParamslug',
}, },
}, },
], ],
...@@ -2464,67 +2464,67 @@ const runTests = (isDev = false, isTurbo = false) => { ...@@ -2464,67 +2464,67 @@ const runTests = (isDev = false, isTurbo = false) => {
}, },
dynamicRoutes: [ dynamicRoutes: [
{ {
namedRegex: '^/_sport/(?<slug>[^/]+?)(?:/)?$', namedRegex: '^/_sport/(?<nextParamslug>[^/]+?)(?:/)?$',
page: '/_sport/[slug]', page: '/_sport/[slug]',
regex: normalizeRegEx('^\\/_sport\\/([^\\/]+?)(?:\\/)?$'), regex: normalizeRegEx('^\\/_sport\\/([^\\/]+?)(?:\\/)?$'),
routeKeys: { routeKeys: {
slug: 'slug', nextParamslug: 'nextParamslug',
}, },
}, },
{ {
namedRegex: '^/_sport/(?<slug>[^/]+?)/test(?:/)?$', namedRegex: '^/_sport/(?<nextParamslug>[^/]+?)/test(?:/)?$',
page: '/_sport/[slug]/test', page: '/_sport/[slug]/test',
regex: normalizeRegEx('^\\/_sport\\/([^\\/]+?)\\/test(?:\\/)?$'), regex: normalizeRegEx('^\\/_sport\\/([^\\/]+?)\\/test(?:\\/)?$'),
routeKeys: { routeKeys: {
slug: 'slug', nextParamslug: 'nextParamslug',
}, },
}, },
{ {
namedRegex: '^/another/(?<id>[^/]+?)(?:/)?$', namedRegex: '^/another/(?<nextParamid>[^/]+?)(?:/)?$',
page: '/another/[id]', page: '/another/[id]',
regex: normalizeRegEx('^\\/another\\/([^\\/]+?)(?:\\/)?$'), regex: normalizeRegEx('^\\/another\\/([^\\/]+?)(?:\\/)?$'),
routeKeys: { routeKeys: {
id: 'id', nextParamid: 'nextParamid',
}, },
}, },
{ {
namedRegex: '^/api/dynamic/(?<slug>[^/]+?)(?:/)?$', namedRegex: '^/api/dynamic/(?<nextParamslug>[^/]+?)(?:/)?$',
page: '/api/dynamic/[slug]', page: '/api/dynamic/[slug]',
regex: normalizeRegEx('^\\/api\\/dynamic\\/([^\\/]+?)(?:\\/)?$'), regex: normalizeRegEx('^\\/api\\/dynamic\\/([^\\/]+?)(?:\\/)?$'),
routeKeys: { routeKeys: {
slug: 'slug', nextParamslug: 'nextParamslug',
}, },
}, },
{ {
namedRegex: '^/auto\\-export/(?<slug>[^/]+?)(?:/)?$', namedRegex: '^/auto\\-export/(?<nextParamslug>[^/]+?)(?:/)?$',
page: '/auto-export/[slug]', page: '/auto-export/[slug]',
regex: normalizeRegEx('^\\/auto\\-export\\/([^\\/]+?)(?:\\/)?$'), regex: normalizeRegEx('^\\/auto\\-export\\/([^\\/]+?)(?:\\/)?$'),
routeKeys: { routeKeys: {
slug: 'slug', nextParamslug: 'nextParamslug',
}, },
}, },
{ {
namedRegex: '^/blog/(?<post>[^/]+?)(?:/)?$', namedRegex: '^/blog/(?<nextParampost>[^/]+?)(?:/)?$',
page: '/blog/[post]', page: '/blog/[post]',
regex: normalizeRegEx('^\\/blog\\/([^\\/]+?)(?:\\/)?$'), regex: normalizeRegEx('^\\/blog\\/([^\\/]+?)(?:\\/)?$'),
routeKeys: { routeKeys: {
post: 'post', nextParampost: 'nextParampost',
}, },
}, },
{ {
namedRegex: '^/blog\\-catchall/(?<slug>.+?)(?:/)?$', namedRegex: '^/blog\\-catchall/(?<nextParamslug>.+?)(?:/)?$',
page: '/blog-catchall/[...slug]', page: '/blog-catchall/[...slug]',
regex: normalizeRegEx('^\\/blog\\-catchall\\/(.+?)(?:\\/)?$'), regex: normalizeRegEx('^\\/blog\\-catchall\\/(.+?)(?:\\/)?$'),
routeKeys: { routeKeys: {
slug: 'slug', nextParamslug: 'nextParamslug',
}, },
}, },
{ {
namedRegex: '^/overridden/(?<slug>[^/]+?)(?:/)?$', namedRegex: '^/overridden/(?<nextParamslug>[^/]+?)(?:/)?$',
page: '/overridden/[slug]', page: '/overridden/[slug]',
regex: '^\\/overridden\\/([^\\/]+?)(?:\\/)?$', regex: '^\\/overridden\\/([^\\/]+?)(?:\\/)?$',
routeKeys: { routeKeys: {
slug: 'slug', nextParamslug: 'nextParamslug',
}, },
}, },
], ],
......
...@@ -1257,10 +1257,10 @@ function runTests({ dev }) { ...@@ -1257,10 +1257,10 @@ function runTests({ dev }) {
)}\\/b\\/([^\\/]+?)\\.json$`, )}\\/b\\/([^\\/]+?)\\.json$`,
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId buildId
)}/b/(?<a>[^/]+?)\\.json$`, )}/b/(?<nextParama>[^/]+?)\\.json$`,
page: '/b/[123]', page: '/b/[123]',
routeKeys: { routeKeys: {
a: '123', nextParama: 'nextParam123',
}, },
}, },
{ {
...@@ -1269,16 +1269,17 @@ function runTests({ dev }) { ...@@ -1269,16 +1269,17 @@ function runTests({ dev }) {
)}\\/c\\/([^\\/]+?)\\.json$`, )}\\/c\\/([^\\/]+?)\\.json$`,
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId buildId
)}/c/(?<a>[^/]+?)\\.json$`, )}/c/(?<nextParama>[^/]+?)\\.json$`,
page: '/c/[alongparamnameshouldbeallowedeventhoughweird]', page: '/c/[alongparamnameshouldbeallowedeventhoughweird]',
routeKeys: { routeKeys: {
a: 'alongparamnameshouldbeallowedeventhoughweird', nextParama:
'nextParamalongparamnameshouldbeallowedeventhoughweird',
}, },
}, },
{ {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId buildId
)}/p1/p2/all\\-ssg/(?<rest>.+?)\\.json$`, )}/p1/p2/all\\-ssg/(?<nextParamrest>.+?)\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex( `^\\/_next\\/data\\/${escapeRegex(
buildId buildId
...@@ -1286,13 +1287,13 @@ function runTests({ dev }) { ...@@ -1286,13 +1287,13 @@ function runTests({ dev }) {
), ),
page: '/p1/p2/all-ssg/[...rest]', page: '/p1/p2/all-ssg/[...rest]',
routeKeys: { routeKeys: {
rest: 'rest', nextParamrest: 'nextParamrest',
}, },
}, },
{ {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId buildId
)}/p1/p2/nested\\-all\\-ssg/(?<rest>.+?)\\.json$`, )}/p1/p2/nested\\-all\\-ssg/(?<nextParamrest>.+?)\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex( `^\\/_next\\/data\\/${escapeRegex(
buildId buildId
...@@ -1300,13 +1301,13 @@ function runTests({ dev }) { ...@@ -1300,13 +1301,13 @@ function runTests({ dev }) {
), ),
page: '/p1/p2/nested-all-ssg/[...rest]', page: '/p1/p2/nested-all-ssg/[...rest]',
routeKeys: { routeKeys: {
rest: 'rest', nextParamrest: 'nextParamrest',
}, },
}, },
{ {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId buildId
)}/p1/p2/predefined\\-ssg/(?<rest>.+?)\\.json$`, )}/p1/p2/predefined\\-ssg/(?<nextParamrest>.+?)\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex( `^\\/_next\\/data\\/${escapeRegex(
buildId buildId
...@@ -1314,147 +1315,148 @@ function runTests({ dev }) { ...@@ -1314,147 +1315,148 @@ function runTests({ dev }) {
), ),
page: '/p1/p2/predefined-ssg/[...rest]', page: '/p1/p2/predefined-ssg/[...rest]',
routeKeys: { routeKeys: {
rest: 'rest', nextParamrest: 'nextParamrest',
}, },
}, },
], ],
dynamicRoutes: [ dynamicRoutes: [
{ {
namedRegex: '^/b/(?<a>[^/]+?)(?:/)?$', namedRegex: '^/b/(?<nextParama>[^/]+?)(?:/)?$',
page: '/b/[123]', page: '/b/[123]',
regex: normalizeRegEx('^\\/b\\/([^\\/]+?)(?:\\/)?$'), regex: normalizeRegEx('^\\/b\\/([^\\/]+?)(?:\\/)?$'),
routeKeys: { routeKeys: {
a: '123', nextParama: 'nextParam123',
}, },
}, },
{ {
namedRegex: `^/blog/(?<name>[^/]+?)/comment/(?<id>[^/]+?)(?:/)?$`, namedRegex: `^/blog/(?<nextParamname>[^/]+?)/comment/(?<nextParamid>[^/]+?)(?:/)?$`,
page: '/blog/[name]/comment/[id]', page: '/blog/[name]/comment/[id]',
regex: normalizeRegEx( regex: normalizeRegEx(
'^\\/blog\\/([^\\/]+?)\\/comment\\/([^\\/]+?)(?:\\/)?$' '^\\/blog\\/([^\\/]+?)\\/comment\\/([^\\/]+?)(?:\\/)?$'
), ),
routeKeys: { routeKeys: {
name: 'name', nextParamname: 'nextParamname',
id: 'id', nextParamid: 'nextParamid',
}, },
}, },
{ {
namedRegex: '^/c/(?<a>[^/]+?)(?:/)?$', namedRegex: '^/c/(?<nextParama>[^/]+?)(?:/)?$',
page: '/c/[alongparamnameshouldbeallowedeventhoughweird]', page: '/c/[alongparamnameshouldbeallowedeventhoughweird]',
regex: normalizeRegEx('^\\/c\\/([^\\/]+?)(?:\\/)?$'), regex: normalizeRegEx('^\\/c\\/([^\\/]+?)(?:\\/)?$'),
routeKeys: { routeKeys: {
a: 'alongparamnameshouldbeallowedeventhoughweird', nextParama:
'nextParamalongparamnameshouldbeallowedeventhoughweird',
}, },
}, },
{ {
namedRegex: '^/catchall\\-dash/(?<helloworld>.+?)(?:/)?$', namedRegex: '^/catchall\\-dash/(?<nextParamhelloworld>.+?)(?:/)?$',
page: '/catchall-dash/[...hello-world]', page: '/catchall-dash/[...hello-world]',
regex: normalizeRegEx('^\\/catchall\\-dash\\/(.+?)(?:\\/)?$'), regex: normalizeRegEx('^\\/catchall\\-dash\\/(.+?)(?:\\/)?$'),
routeKeys: { routeKeys: {
helloworld: 'hello-world', nextParamhelloworld: 'nextParamhello-world',
}, },
}, },
{ {
namedRegex: '^/d/(?<id>[^/]+?)(?:/)?$', namedRegex: '^/d/(?<nextParamid>[^/]+?)(?:/)?$',
page: '/d/[id]', page: '/d/[id]',
regex: normalizeRegEx('^\\/d\\/([^\\/]+?)(?:\\/)?$'), regex: normalizeRegEx('^\\/d\\/([^\\/]+?)(?:\\/)?$'),
routeKeys: { routeKeys: {
id: 'id', nextParamid: 'nextParamid',
}, },
}, },
{ {
namedRegex: '^/dash/(?<helloworld>[^/]+?)(?:/)?$', namedRegex: '^/dash/(?<nextParamhelloworld>[^/]+?)(?:/)?$',
page: '/dash/[hello-world]', page: '/dash/[hello-world]',
regex: normalizeRegEx('^\\/dash\\/([^\\/]+?)(?:\\/)?$'), regex: normalizeRegEx('^\\/dash\\/([^\\/]+?)(?:\\/)?$'),
routeKeys: { routeKeys: {
helloworld: 'hello-world', nextParamhelloworld: 'nextParamhello-world',
}, },
}, },
{ {
namedRegex: '^/index/(?<slug>.+?)(?:/)?$', namedRegex: '^/index/(?<nextParamslug>.+?)(?:/)?$',
page: '/index/[...slug]', page: '/index/[...slug]',
regex: normalizeRegEx('^/index/(.+?)(?:/)?$'), regex: normalizeRegEx('^/index/(.+?)(?:/)?$'),
routeKeys: { routeKeys: {
slug: 'slug', nextParamslug: 'nextParamslug',
}, },
}, },
{ {
namedRegex: `^/on\\-mount/(?<post>[^/]+?)(?:/)?$`, namedRegex: `^/on\\-mount/(?<nextParampost>[^/]+?)(?:/)?$`,
page: '/on-mount/[post]', page: '/on-mount/[post]',
regex: normalizeRegEx('^\\/on\\-mount\\/([^\\/]+?)(?:\\/)?$'), regex: normalizeRegEx('^\\/on\\-mount\\/([^\\/]+?)(?:\\/)?$'),
routeKeys: { routeKeys: {
post: 'post', nextParampost: 'nextParampost',
}, },
}, },
{ {
namedRegex: `^/p1/p2/all\\-ssg/(?<rest>.+?)(?:/)?$`, namedRegex: `^/p1/p2/all\\-ssg/(?<nextParamrest>.+?)(?:/)?$`,
page: '/p1/p2/all-ssg/[...rest]', page: '/p1/p2/all-ssg/[...rest]',
regex: normalizeRegEx('^\\/p1\\/p2\\/all\\-ssg\\/(.+?)(?:\\/)?$'), regex: normalizeRegEx('^\\/p1\\/p2\\/all\\-ssg\\/(.+?)(?:\\/)?$'),
routeKeys: { routeKeys: {
rest: 'rest', nextParamrest: 'nextParamrest',
}, },
}, },
{ {
namedRegex: `^/p1/p2/all\\-ssr/(?<rest>.+?)(?:/)?$`, namedRegex: `^/p1/p2/all\\-ssr/(?<nextParamrest>.+?)(?:/)?$`,
page: '/p1/p2/all-ssr/[...rest]', page: '/p1/p2/all-ssr/[...rest]',
regex: normalizeRegEx('^\\/p1\\/p2\\/all\\-ssr\\/(.+?)(?:\\/)?$'), regex: normalizeRegEx('^\\/p1\\/p2\\/all\\-ssr\\/(.+?)(?:\\/)?$'),
routeKeys: { routeKeys: {
rest: 'rest', nextParamrest: 'nextParamrest',
}, },
}, },
{ {
namedRegex: `^/p1/p2/nested\\-all\\-ssg/(?<rest>.+?)(?:/)?$`, namedRegex: `^/p1/p2/nested\\-all\\-ssg/(?<nextParamrest>.+?)(?:/)?$`,
page: '/p1/p2/nested-all-ssg/[...rest]', page: '/p1/p2/nested-all-ssg/[...rest]',
regex: normalizeRegEx( regex: normalizeRegEx(
'^\\/p1\\/p2\\/nested\\-all\\-ssg\\/(.+?)(?:\\/)?$' '^\\/p1\\/p2\\/nested\\-all\\-ssg\\/(.+?)(?:\\/)?$'
), ),
routeKeys: { routeKeys: {
rest: 'rest', nextParamrest: 'nextParamrest',
}, },
}, },
{ {
namedRegex: `^/p1/p2/predefined\\-ssg/(?<rest>.+?)(?:/)?$`, namedRegex: `^/p1/p2/predefined\\-ssg/(?<nextParamrest>.+?)(?:/)?$`,
page: '/p1/p2/predefined-ssg/[...rest]', page: '/p1/p2/predefined-ssg/[...rest]',
regex: normalizeRegEx( regex: normalizeRegEx(
'^\\/p1\\/p2\\/predefined\\-ssg\\/(.+?)(?:\\/)?$' '^\\/p1\\/p2\\/predefined\\-ssg\\/(.+?)(?:\\/)?$'
), ),
routeKeys: { routeKeys: {
rest: 'rest', nextParamrest: 'nextParamrest',
}, },
}, },
{ {
namedRegex: `^/(?<name>[^/]+?)(?:/)?$`, namedRegex: `^/(?<nextParamname>[^/]+?)(?:/)?$`,
page: '/[name]', page: '/[name]',
regex: normalizeRegEx('^\\/([^\\/]+?)(?:\\/)?$'), regex: normalizeRegEx('^\\/([^\\/]+?)(?:\\/)?$'),
routeKeys: { routeKeys: {
name: 'name', nextParamname: 'nextParamname',
}, },
}, },
{ {
namedRegex: `^/(?<name>[^/]+?)/comments(?:/)?$`, namedRegex: `^/(?<nextParamname>[^/]+?)/comments(?:/)?$`,
page: '/[name]/comments', page: '/[name]/comments',
regex: normalizeRegEx('^\\/([^\\/]+?)\\/comments(?:\\/)?$'), regex: normalizeRegEx('^\\/([^\\/]+?)\\/comments(?:\\/)?$'),
routeKeys: { routeKeys: {
name: 'name', nextParamname: 'nextParamname',
}, },
}, },
{ {
namedRegex: `^/(?<name>[^/]+?)/on\\-mount\\-redir(?:/)?$`, namedRegex: `^/(?<nextParamname>[^/]+?)/on\\-mount\\-redir(?:/)?$`,
page: '/[name]/on-mount-redir', page: '/[name]/on-mount-redir',
regex: normalizeRegEx( regex: normalizeRegEx(
'^\\/([^\\/]+?)\\/on\\-mount\\-redir(?:\\/)?$' '^\\/([^\\/]+?)\\/on\\-mount\\-redir(?:\\/)?$'
), ),
routeKeys: { routeKeys: {
name: 'name', nextParamname: 'nextParamname',
}, },
}, },
{ {
namedRegex: `^/(?<name>[^/]+?)/(?<comment>[^/]+?)(?:/)?$`, namedRegex: `^/(?<nextParamname>[^/]+?)/(?<nextParamcomment>[^/]+?)(?:/)?$`,
page: '/[name]/[comment]', page: '/[name]/[comment]',
regex: normalizeRegEx('^\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$'), regex: normalizeRegEx('^\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$'),
routeKeys: { routeKeys: {
name: 'name', nextParamname: 'nextParamname',
comment: 'comment', nextParamcomment: 'nextParamcomment',
}, },
}, },
], ],
......
...@@ -193,7 +193,7 @@ describe('Required Server Files', () => { ...@@ -193,7 +193,7 @@ describe('Required Server Files', () => {
it('should render dynamic SSR page correctly with x-matched-path', async () => { it('should render dynamic SSR page correctly with x-matched-path', async () => {
const html = await renderViaHTTP( const html = await renderViaHTTP(
appPort, appPort,
'/some-other-path?slug=first', '/some-other-path?nextParamslug=first',
undefined, undefined,
{ {
headers: { headers: {
...@@ -259,7 +259,7 @@ describe('Required Server Files', () => { ...@@ -259,7 +259,7 @@ describe('Required Server Files', () => {
it('should return data correctly with x-matched-path', async () => { it('should return data correctly with x-matched-path', async () => {
const res = await fetchViaHTTP( const res = await fetchViaHTTP(
appPort, appPort,
`/_next/data/${buildId}/dynamic/first.json?slug=first`, `/_next/data/${buildId}/dynamic/first.json?nextParamslug=first`,
undefined, undefined,
{ {
headers: { headers: {
......
...@@ -89,7 +89,7 @@ async function createNextInstall({ ...@@ -89,7 +89,7 @@ async function createNextInstall({
let combinedDependencies = dependencies let combinedDependencies = dependencies
if (!(packageJson && packageJson.nextPrivateSkipLocalDeps)) { if (!(packageJson && packageJson.nextParamateSkipLocalDeps)) {
const pkgPaths = await rootSpan const pkgPaths = await rootSpan
.traceChild('linkPackages') .traceChild('linkPackages')
.traceAsyncFn(() => .traceAsyncFn(() =>
......
...@@ -313,7 +313,7 @@ describe('should set-up next', () => { ...@@ -313,7 +313,7 @@ describe('should set-up next', () => {
it('should render dynamic SSR page correctly with x-matched-path', async () => { it('should render dynamic SSR page correctly with x-matched-path', async () => {
const html = await renderViaHTTP( const html = await renderViaHTTP(
appPort, appPort,
'/some-other-path?slug=first', '/some-other-path?nextParamslug=first',
undefined, undefined,
{ {
headers: { headers: {
...@@ -330,7 +330,7 @@ describe('should set-up next', () => { ...@@ -330,7 +330,7 @@ describe('should set-up next', () => {
const html2 = await renderViaHTTP( const html2 = await renderViaHTTP(
appPort, appPort,
'/some-other-path?slug=second', '/some-other-path?nextParamslug=second',
undefined, undefined,
{ {
headers: { headers: {
...@@ -393,7 +393,7 @@ describe('should set-up next', () => { ...@@ -393,7 +393,7 @@ describe('should set-up next', () => {
it('should return data correctly with x-matched-path', async () => { it('should return data correctly with x-matched-path', async () => {
const res = await fetchViaHTTP( const res = await fetchViaHTTP(
appPort, appPort,
`/_next/data/${next.buildId}/en/dynamic/first.json?slug=first`, `/_next/data/${next.buildId}/en/dynamic/first.json?nextParamslug=first`,
undefined, undefined,
{ {
headers: { headers: {
...@@ -640,7 +640,7 @@ describe('should set-up next', () => { ...@@ -640,7 +640,7 @@ describe('should set-up next', () => {
const res = await fetchViaHTTP( const res = await fetchViaHTTP(
appPort, appPort,
'/optional-ssp', '/optional-ssp',
{ rest: '', another: 'value' }, { nextParamrest: '', another: 'value' },
{ {
headers: { headers: {
'x-matched-path': '/optional-ssp/[[...rest]]', 'x-matched-path': '/optional-ssp/[[...rest]]',
...@@ -722,7 +722,7 @@ describe('should set-up next', () => { ...@@ -722,7 +722,7 @@ describe('should set-up next', () => {
const res = await fetchViaHTTP( const res = await fetchViaHTTP(
appPort, appPort,
'/api/optional', '/api/optional',
{ rest: '', another: 'value' }, { nextParamrest: '', another: 'value' },
{ {
headers: { headers: {
'x-matched-path': '/api/optional/[[...rest]]', 'x-matched-path': '/api/optional/[[...rest]]',
......
...@@ -570,7 +570,7 @@ describe('should set-up next', () => { ...@@ -570,7 +570,7 @@ describe('should set-up next', () => {
it('should render dynamic SSR page correctly with x-matched-path', async () => { it('should render dynamic SSR page correctly with x-matched-path', async () => {
const html = await renderViaHTTP( const html = await renderViaHTTP(
appPort, appPort,
'/some-other-path?slug=first', '/some-other-path?nextParamslug=first',
undefined, undefined,
{ {
headers: { headers: {
...@@ -587,7 +587,7 @@ describe('should set-up next', () => { ...@@ -587,7 +587,7 @@ describe('should set-up next', () => {
const html2 = await renderViaHTTP( const html2 = await renderViaHTTP(
appPort, appPort,
'/some-other-path?slug=second', '/some-other-path?nextParamslug=second',
undefined, undefined,
{ {
headers: { headers: {
...@@ -703,7 +703,7 @@ describe('should set-up next', () => { ...@@ -703,7 +703,7 @@ describe('should set-up next', () => {
it('should return data correctly with x-matched-path', async () => { it('should return data correctly with x-matched-path', async () => {
const res = await fetchViaHTTP( const res = await fetchViaHTTP(
appPort, appPort,
`/_next/data/${next.buildId}/dynamic/first.json?slug=first`, `/_next/data/${next.buildId}/dynamic/first.json?nextParamslug=first`,
undefined, undefined,
{ {
headers: { headers: {
...@@ -1145,7 +1145,7 @@ describe('should set-up next', () => { ...@@ -1145,7 +1145,7 @@ describe('should set-up next', () => {
const res = await fetchViaHTTP( const res = await fetchViaHTTP(
appPort, appPort,
'/api/optional/index', '/api/optional/index',
{ rest: 'index', another: 'value' }, { nextParamrest: 'index', another: 'value' },
{ {
headers: { headers: {
'x-matched-path': '/api/optional/[[...rest]]', 'x-matched-path': '/api/optional/[[...rest]]',
......
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