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

Ensure dynamic routes dont match _next/static unexpectedly (#62559)

This ensures our dynamic routes that have the same specificity as
`_next/static/:path*` don't get matched unexpectedly when the
`_next/static` asset doesn't exist. We were holding off on making this
change explicit due to compatibility concerns but these are no longer a
concern and the unexpected matching is more of a concern.

Closes: CSM-11
Fixes: https://github.com/vercel/next.js/issues/19270

Closes NEXT-2613
parent f052fa8d
...@@ -179,6 +179,7 @@ import { TurbopackManifestLoader } from '../server/dev/turbopack/manifest-loader ...@@ -179,6 +179,7 @@ import { TurbopackManifestLoader } from '../server/dev/turbopack/manifest-loader
import type { Entrypoints } from '../server/dev/turbopack/types' import type { Entrypoints } from '../server/dev/turbopack/types'
import { buildCustomRoute } from '../lib/build-custom-route' import { buildCustomRoute } from '../lib/build-custom-route'
import { createProgress } from './progress' import { createProgress } from './progress'
import { modifyRouteRegex } from '../lib/redirect-status'
interface ExperimentalBypassForInfo { interface ExperimentalBypassForInfo {
experimentalBypassFor?: RouteHas[] experimentalBypassFor?: RouteHas[]
...@@ -284,13 +285,17 @@ export type RoutesManifest = { ...@@ -284,13 +285,17 @@ export type RoutesManifest = {
caseSensitive?: boolean caseSensitive?: boolean
} }
function pageToRoute(page: string) { function pageToRoute(page: string, restrictedPaths?: string[]) {
const routeRegex = getNamedRouteRegex(page, true) const routeRegex = getNamedRouteRegex(page, true)
return { return {
page, page,
regex: normalizeRouteRegex(routeRegex.re.source), regex: normalizeRouteRegex(
restrictedPaths?.length
? modifyRouteRegex(routeRegex.re.source, restrictedPaths)
: routeRegex.re.source
),
routeKeys: routeRegex.routeKeys, routeKeys: routeRegex.routeKeys,
namedRegex: routeRegex.namedRegex, namedRegex: modifyRouteRegex(routeRegex.namedRegex, restrictedPaths),
} }
} }
...@@ -1087,6 +1092,9 @@ export default async function build( ...@@ -1087,6 +1092,9 @@ export default async function build(
const restrictedRedirectPaths = ['/_next'].map((p) => const restrictedRedirectPaths = ['/_next'].map((p) =>
config.basePath ? `${config.basePath}${p}` : p config.basePath ? `${config.basePath}${p}` : p
) )
const restrictedDynamicPaths = ['/_next/static'].map((p) =>
config.basePath ? `${config.basePath}${p}` : p
)
const routesManifestPath = path.join(distDir, ROUTES_MANIFEST) const routesManifestPath = path.join(distDir, ROUTES_MANIFEST)
const routesManifest: RoutesManifest = nextBuildSpan const routesManifest: RoutesManifest = nextBuildSpan
...@@ -1101,7 +1109,7 @@ export default async function build( ...@@ -1101,7 +1109,7 @@ export default async function build(
for (const route of sortedRoutes) { for (const route of sortedRoutes) {
if (isDynamicRoute(route)) { if (isDynamicRoute(route)) {
dynamicRoutes.push(pageToRoute(route)) dynamicRoutes.push(pageToRoute(route, restrictedDynamicPaths))
} else if (!isReservedPage(route)) { } else if (!isReservedPage(route)) {
staticRoutes.push(pageToRoute(route)) staticRoutes.push(pageToRoute(route))
} }
......
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
type RouteMatchFn, type RouteMatchFn,
} from '../../../shared/lib/router/utils/route-matcher' } from '../../../shared/lib/router/utils/route-matcher'
import { getRouteRegex } from '../../../shared/lib/router/utils/route-regex' import { getRouteRegex } from '../../../shared/lib/router/utils/route-regex'
import { modifyRouteRegex } from '../../../lib/redirect-status'
type RouteMatchResult = { type RouteMatchResult = {
params?: Record<string, string | string[]> params?: Record<string, string | string[]>
...@@ -24,7 +25,13 @@ export class RouteMatcher<D extends RouteDefinition = RouteDefinition> { ...@@ -24,7 +25,13 @@ export class RouteMatcher<D extends RouteDefinition = RouteDefinition> {
constructor(public readonly definition: D) { constructor(public readonly definition: D) {
if (isDynamicRoute(definition.pathname)) { if (isDynamicRoute(definition.pathname)) {
this.dynamic = getRouteMatcher(getRouteRegex(definition.pathname)) const routeRegex = getRouteRegex(definition.pathname)
const origRegex = routeRegex.re.toString()
const modifiedRegex = modifyRouteRegex(origRegex, ['/_next/static'])
routeRegex.re = new RegExp(
modifiedRegex.substring(1, modifiedRegex.length - 1)
)
this.dynamic = getRouteMatcher(routeRegex)
} }
} }
......
...@@ -3,7 +3,12 @@ import cheerio from 'cheerio' ...@@ -3,7 +3,12 @@ import cheerio from 'cheerio'
import { promisify } from 'util' import { promisify } from 'util'
import { join } from 'path' import { join } from 'path'
import { createNextDescribe } from 'e2e-utils' import { createNextDescribe } from 'e2e-utils'
import { check, fetchViaHTTP, normalizeRegEx, waitFor } from 'next-test-utils' import {
check,
fetchViaHTTP,
normalizeRouteRegExes,
waitFor,
} from 'next-test-utils'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
const glob = promisify(globOrig) const glob = promisify(globOrig)
...@@ -728,13 +733,7 @@ createNextDescribe( ...@@ -728,13 +733,7 @@ createNextDescribe(
for (const key of Object.keys(curManifest.dynamicRoutes)) { for (const key of Object.keys(curManifest.dynamicRoutes)) {
const item = curManifest.dynamicRoutes[key] const item = curManifest.dynamicRoutes[key]
normalizeRouteRegExes(item)
if (item.dataRouteRegex) {
item.dataRouteRegex = normalizeRegEx(item.dataRouteRegex)
}
if (item.routeRegex) {
item.routeRegex = normalizeRegEx(item.routeRegex)
}
} }
for (const key of Object.keys(curManifest.routes)) { for (const key of Object.keys(curManifest.routes)) {
...@@ -1506,7 +1505,7 @@ createNextDescribe( ...@@ -1506,7 +1505,7 @@ createNextDescribe(
}, },
], ],
"fallback": null, "fallback": null,
"routeRegex": "^\\/articles\\/([^\\/]+?)(?:\\/)?$", "routeRegex": "^\\/articles\\/([^\\/]+?)?$",
}, },
"/blog/[author]": { "/blog/[author]": {
"dataRoute": "/blog/[author].rsc", "dataRoute": "/blog/[author].rsc",
...@@ -1523,7 +1522,7 @@ createNextDescribe( ...@@ -1523,7 +1522,7 @@ createNextDescribe(
}, },
], ],
"fallback": false, "fallback": false,
"routeRegex": "^\\/blog\\/([^\\/]+?)(?:\\/)?$", "routeRegex": "^\\/blog\\/([^\\/]+?)?$",
}, },
"/blog/[author]/[slug]": { "/blog/[author]/[slug]": {
"dataRoute": "/blog/[author]/[slug].rsc", "dataRoute": "/blog/[author]/[slug].rsc",
...@@ -1540,7 +1539,7 @@ createNextDescribe( ...@@ -1540,7 +1539,7 @@ createNextDescribe(
}, },
], ],
"fallback": null, "fallback": null,
"routeRegex": "^\\/blog\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$", "routeRegex": "^\\/blog\\/([^\\/]+?)\\/([^\\/]+?)?$",
}, },
"/dynamic-error/[id]": { "/dynamic-error/[id]": {
"dataRoute": "/dynamic-error/[id].rsc", "dataRoute": "/dynamic-error/[id].rsc",
...@@ -1557,7 +1556,7 @@ createNextDescribe( ...@@ -1557,7 +1556,7 @@ createNextDescribe(
}, },
], ],
"fallback": null, "fallback": null,
"routeRegex": "^\\/dynamic\\-error\\/([^\\/]+?)(?:\\/)?$", "routeRegex": "^\\/dynamic\\-error\\/([^\\/]+?)?$",
}, },
"/force-static/[slug]": { "/force-static/[slug]": {
"dataRoute": "/force-static/[slug].rsc", "dataRoute": "/force-static/[slug].rsc",
...@@ -1574,7 +1573,7 @@ createNextDescribe( ...@@ -1574,7 +1573,7 @@ createNextDescribe(
}, },
], ],
"fallback": null, "fallback": null,
"routeRegex": "^\\/force\\-static\\/([^\\/]+?)(?:\\/)?$", "routeRegex": "^\\/force\\-static\\/([^\\/]+?)?$",
}, },
"/gen-params-dynamic-revalidate/[slug]": { "/gen-params-dynamic-revalidate/[slug]": {
"dataRoute": "/gen-params-dynamic-revalidate/[slug].rsc", "dataRoute": "/gen-params-dynamic-revalidate/[slug].rsc",
...@@ -1591,7 +1590,7 @@ createNextDescribe( ...@@ -1591,7 +1590,7 @@ createNextDescribe(
}, },
], ],
"fallback": null, "fallback": null,
"routeRegex": "^\\/gen\\-params\\-dynamic\\-revalidate\\/([^\\/]+?)(?:\\/)?$", "routeRegex": "^\\/gen\\-params\\-dynamic\\-revalidate\\/([^\\/]+?)?$",
}, },
"/hooks/use-pathname/[slug]": { "/hooks/use-pathname/[slug]": {
"dataRoute": "/hooks/use-pathname/[slug].rsc", "dataRoute": "/hooks/use-pathname/[slug].rsc",
...@@ -1608,7 +1607,7 @@ createNextDescribe( ...@@ -1608,7 +1607,7 @@ createNextDescribe(
}, },
], ],
"fallback": null, "fallback": null,
"routeRegex": "^\\/hooks\\/use\\-pathname\\/([^\\/]+?)(?:\\/)?$", "routeRegex": "^\\/hooks\\/use\\-pathname\\/([^\\/]+?)?$",
}, },
"/partial-gen-params-no-additional-lang/[lang]/[slug]": { "/partial-gen-params-no-additional-lang/[lang]/[slug]": {
"dataRoute": "/partial-gen-params-no-additional-lang/[lang]/[slug].rsc", "dataRoute": "/partial-gen-params-no-additional-lang/[lang]/[slug].rsc",
...@@ -1625,7 +1624,7 @@ createNextDescribe( ...@@ -1625,7 +1624,7 @@ createNextDescribe(
}, },
], ],
"fallback": false, "fallback": false,
"routeRegex": "^\\/partial\\-gen\\-params\\-no\\-additional\\-lang\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$", "routeRegex": "^\\/partial\\-gen\\-params\\-no\\-additional\\-lang\\/([^\\/]+?)\\/([^\\/]+?)?$",
}, },
"/partial-gen-params-no-additional-slug/[lang]/[slug]": { "/partial-gen-params-no-additional-slug/[lang]/[slug]": {
"dataRoute": "/partial-gen-params-no-additional-slug/[lang]/[slug].rsc", "dataRoute": "/partial-gen-params-no-additional-slug/[lang]/[slug].rsc",
...@@ -1642,7 +1641,7 @@ createNextDescribe( ...@@ -1642,7 +1641,7 @@ createNextDescribe(
}, },
], ],
"fallback": false, "fallback": false,
"routeRegex": "^\\/partial\\-gen\\-params\\-no\\-additional\\-slug\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$", "routeRegex": "^\\/partial\\-gen\\-params\\-no\\-additional\\-slug\\/([^\\/]+?)\\/([^\\/]+?)?$",
}, },
"/ssg-draft-mode/[[...route]]": { "/ssg-draft-mode/[[...route]]": {
"dataRoute": "/ssg-draft-mode/[[...route]].rsc", "dataRoute": "/ssg-draft-mode/[[...route]].rsc",
...@@ -1659,7 +1658,7 @@ createNextDescribe( ...@@ -1659,7 +1658,7 @@ createNextDescribe(
}, },
], ],
"fallback": null, "fallback": null,
"routeRegex": "^\\/ssg\\-draft\\-mode(?:\\/(.+?))?(?:\\/)?$", "routeRegex": "^\\/ssg\\-draft\\-mode(?:\\/(.+?))?$",
}, },
"/static-to-dynamic-error-forced/[id]": { "/static-to-dynamic-error-forced/[id]": {
"dataRoute": "/static-to-dynamic-error-forced/[id].rsc", "dataRoute": "/static-to-dynamic-error-forced/[id].rsc",
...@@ -1676,7 +1675,7 @@ createNextDescribe( ...@@ -1676,7 +1675,7 @@ createNextDescribe(
}, },
], ],
"fallback": null, "fallback": null,
"routeRegex": "^\\/static\\-to\\-dynamic\\-error\\-forced\\/([^\\/]+?)(?:\\/)?$", "routeRegex": "^\\/static\\-to\\-dynamic\\-error\\-forced\\/([^\\/]+?)?$",
}, },
} }
`) `)
......
import { createNextDescribe } from 'e2e-utils' import { createNextDescribe } from 'e2e-utils'
import { fetchViaHTTP, normalizeRegEx } from 'next-test-utils' import { fetchViaHTTP, normalizeRouteRegExes } from 'next-test-utils'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { join } from 'path' import { join } from 'path'
import escapeStringRegexp from 'escape-string-regexp' import escapeStringRegexp from 'escape-string-regexp'
...@@ -151,31 +151,31 @@ createNextDescribe( ...@@ -151,31 +151,31 @@ createNextDescribe(
) )
for (const route of manifest.dataRoutes) { for (const route of manifest.dataRoutes) {
route.dataRouteRegex = normalizeRegEx(route.dataRouteRegex) normalizeRouteRegExes(route)
} }
expect(manifest.dataRoutes).toEqual([ expect(manifest.dataRoutes).toEqual(
{ [
dataRouteRegex: normalizeRegEx( {
`^/_next/data/${escapeStringRegexp(next.buildId)}/index.json$` dataRouteRegex: `^/_next/data/${escapeStringRegexp(
),
page: '/',
},
{
dataRouteRegex: normalizeRegEx(
`^/_next/data/${escapeStringRegexp(
next.buildId next.buildId
)}/([^/]+?)\\.json$` )}/index.json$`,
), page: '/',
namedDataRouteRegex: `^/_next/data/${escapeStringRegexp(
next.buildId
)}/(?<nxtPid>[^/]+?)\\.json$`,
page: '/[id]',
routeKeys: {
nxtPid: 'nxtPid',
}, },
}, {
]) dataRouteRegex: `^/_next/data/${escapeStringRegexp(
next.buildId
)}/([^/]+?)\\.json$`,
namedDataRouteRegex: `^/_next/data/${escapeStringRegexp(
next.buildId
)}/(?<nxtPid>[^/]+?)\\.json$`,
page: '/[id]',
routeKeys: {
nxtPid: 'nxtPid',
},
},
].map((item) => normalizeRouteRegExes(item))
)
}) })
} }
} }
......
...@@ -8,7 +8,7 @@ import { ...@@ -8,7 +8,7 @@ import {
fetchViaHTTP, fetchViaHTTP,
getBrowserBodyText, getBrowserBodyText,
getRedboxHeader, getRedboxHeader,
normalizeRegEx, normalizeRouteRegExes,
renderViaHTTP, renderViaHTTP,
waitFor, waitFor,
} from 'next-test-utils' } from 'next-test-utils'
...@@ -21,180 +21,6 @@ const appDir = join(__dirname, '../app') ...@@ -21,180 +21,6 @@ const appDir = join(__dirname, '../app')
let buildId let buildId
let next: NextInstance let next: NextInstance
const expectedManifestRoutes = () => [
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/index.json$`
),
page: '/',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/another.json$`
),
page: '/another',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/blog.json$`
),
page: '/blog',
},
{
namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId
)}/blog/(?<nxtPpost>[^/]+?)\\.json$`,
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/blog\\/([^\\/]+?)\\.json$`
),
page: '/blog/[post]',
routeKeys: {
nxtPpost: 'nxtPpost',
},
},
{
namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId
)}/blog/(?<nxtPpost>[^/]+?)/(?<nxtPcomment>[^/]+?)\\.json$`,
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/blog\\/([^\\/]+?)\\/([^\\/]+?)\\.json$`
),
page: '/blog/[post]/[comment]',
routeKeys: {
nxtPpost: 'nxtPpost',
nxtPcomment: 'nxtPcomment',
},
},
{
namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId
)}/catchall/(?<nxtPpath>.+?)\\.json$`,
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/catchall\\/(.+?)\\.json$`
),
page: '/catchall/[...path]',
routeKeys: {
nxtPpath: 'nxtPpath',
},
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/custom-cache.json$`
),
page: '/custom-cache',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/default-revalidate.json$`
),
page: '/default-revalidate',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/early-request-end.json$`,
page: '/early-request-end',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/enoent.json$`
),
page: '/enoent',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/invalid-keys.json$`
),
page: '/invalid-keys',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/non-json.json$`
),
page: '/non-json',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/not-found.json$`,
page: '/not-found',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/not\\-found\\/([^\\/]+?)\\.json$`,
namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId
)}/not\\-found/(?<nxtPslug>[^/]+?)\\.json$`,
page: '/not-found/[slug]',
routeKeys: {
nxtPslug: 'nxtPslug',
},
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/promise.json$`
),
page: '/promise',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/promise\\/mutate-res.json$`
),
page: '/promise/mutate-res',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/promise\\/mutate-res-no-streaming.json$`
),
page: '/promise/mutate-res-no-streaming',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/promise\\/mutate-res-props.json$`
),
page: '/promise/mutate-res-props',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/refresh.json$`
),
page: '/refresh',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/slow.json$`
),
page: '/slow',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/something.json$`
),
page: '/something',
},
{
namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId
)}/user/(?<nxtPuser>[^/]+?)/profile\\.json$`,
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/user\\/([^\\/]+?)\\/profile\\.json$`
),
page: '/user/[user]/profile',
routeKeys: {
nxtPuser: 'nxtPuser',
},
},
]
const navigateTest = () => { const navigateTest = () => {
it('should navigate between pages successfully', async () => { it('should navigate between pages successfully', async () => {
const toBuild = [ const toBuild = [
...@@ -789,10 +615,176 @@ const runTests = (isDev = false, isDeploy = false) => { ...@@ -789,10 +615,176 @@ const runTests = (isDev = false, isDeploy = false) => {
await next.readFile('.next/routes-manifest.json') await next.readFile('.next/routes-manifest.json')
) )
for (const route of dataRoutes) { for (const route of dataRoutes) {
route.dataRouteRegex = normalizeRegEx(route.dataRouteRegex) normalizeRouteRegExes(route)
} }
expect(dataRoutes).toEqual(expectedManifestRoutes()) expect(dataRoutes).toEqual(
[
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/index.json$`,
page: '/',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/another.json$`,
page: '/another',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/blog.json$`,
page: '/blog',
},
{
namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId
)}/blog/(?<nxtPpost>[^/]+?)\\.json$`,
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/blog\\/([^\\/]+?)\\.json$`,
page: '/blog/[post]',
routeKeys: {
nxtPpost: 'nxtPpost',
},
},
{
namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId
)}/blog/(?<nxtPpost>[^/]+?)/(?<nxtPcomment>[^/]+?)\\.json$`,
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/blog\\/([^\\/]+?)\\/([^\\/]+?)\\.json$`,
page: '/blog/[post]/[comment]',
routeKeys: {
nxtPpost: 'nxtPpost',
nxtPcomment: 'nxtPcomment',
},
},
{
namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId
)}/catchall/(?<nxtPpath>.+?)\\.json$`,
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/catchall\\/(.+?)\\.json$`,
page: '/catchall/[...path]',
routeKeys: {
nxtPpath: 'nxtPpath',
},
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/custom-cache.json$`,
page: '/custom-cache',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/default-revalidate.json$`,
page: '/default-revalidate',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/early-request-end.json$`,
page: '/early-request-end',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/enoent.json$`,
page: '/enoent',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/invalid-keys.json$`,
page: '/invalid-keys',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/non-json.json$`,
page: '/non-json',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/not-found.json$`,
page: '/not-found',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/not\\-found\\/([^\\/]+?)\\.json$`,
namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId
)}/not\\-found/(?<nxtPslug>[^/]+?)\\.json$`,
page: '/not-found/[slug]',
routeKeys: {
nxtPslug: 'nxtPslug',
},
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/promise.json$`,
page: '/promise',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/promise\\/mutate-res.json$`,
page: '/promise/mutate-res',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/promise\\/mutate-res-no-streaming.json$`,
page: '/promise/mutate-res-no-streaming',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/promise\\/mutate-res-props.json$`,
page: '/promise/mutate-res-props',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/refresh.json$`,
page: '/refresh',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/slow.json$`,
page: '/slow',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/something.json$`,
page: '/something',
},
{
namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId
)}/user/(?<nxtPuser>[^/]+?)/profile\\.json$`,
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/user\\/([^\\/]+?)\\/profile\\.json$`,
page: '/user/[user]/profile',
routeKeys: {
nxtPuser: 'nxtPuser',
},
},
].map((item) => normalizeRouteRegExes(item))
)
}) })
} }
......
...@@ -11,7 +11,7 @@ import { ...@@ -11,7 +11,7 @@ import {
getBrowserBodyText, getBrowserBodyText,
getRedboxHeader, getRedboxHeader,
hasRedbox, hasRedbox,
normalizeRegEx, normalizeRouteRegExes,
renderViaHTTP, renderViaHTTP,
waitFor, waitFor,
} from 'next-test-utils' } from 'next-test-utils'
...@@ -89,205 +89,6 @@ describe('Prerender', () => { ...@@ -89,205 +89,6 @@ describe('Prerender', () => {
return !cacheControl || !/no-store/.test(cacheControl) return !cacheControl || !/no-store/.test(cacheControl)
} }
const expectedManifestRoutes = () => ({
'/': {
dataRoute: `/_next/data/${next.buildId}/index.json`,
initialRevalidateSeconds: 2,
srcRoute: null,
},
'/blog/[post3]': {
dataRoute: `/_next/data/${next.buildId}/blog/[post3].json`,
initialRevalidateSeconds: 10,
srcRoute: '/blog/[post]',
},
'/blog/post-1': {
dataRoute: `/_next/data/${next.buildId}/blog/post-1.json`,
initialRevalidateSeconds: 10,
srcRoute: '/blog/[post]',
},
'/blog/post-2': {
dataRoute: `/_next/data/${next.buildId}/blog/post-2.json`,
initialRevalidateSeconds: 10,
srcRoute: '/blog/[post]',
},
'/blog/post-4': {
dataRoute: `/_next/data/${next.buildId}/blog/post-4.json`,
initialRevalidateSeconds: 10,
srcRoute: '/blog/[post]',
},
'/blog/post-1/comment-1': {
dataRoute: `/_next/data/${next.buildId}/blog/post-1/comment-1.json`,
initialRevalidateSeconds: 2,
srcRoute: '/blog/[post]/[comment]',
},
'/blog/post-2/comment-2': {
dataRoute: `/_next/data/${next.buildId}/blog/post-2/comment-2.json`,
initialRevalidateSeconds: 2,
srcRoute: '/blog/[post]/[comment]',
},
'/blog/post.1': {
dataRoute: `/_next/data/${next.buildId}/blog/post.1.json`,
initialRevalidateSeconds: 10,
srcRoute: '/blog/[post]',
},
'/catchall-explicit/another/value': {
dataRoute: `/_next/data/${next.buildId}/catchall-explicit/another/value.json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall-explicit/[...slug]',
},
'/catchall-explicit/first': {
dataRoute: `/_next/data/${next.buildId}/catchall-explicit/first.json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall-explicit/[...slug]',
},
'/catchall-explicit/hello/another': {
dataRoute: `/_next/data/${next.buildId}/catchall-explicit/hello/another.json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall-explicit/[...slug]',
},
'/catchall-explicit/second': {
dataRoute: `/_next/data/${next.buildId}/catchall-explicit/second.json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall-explicit/[...slug]',
},
'/catchall-explicit/[first]/[second]': {
dataRoute: `/_next/data/${next.buildId}/catchall-explicit/[first]/[second].json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall-explicit/[...slug]',
},
'/catchall-explicit/[third]/[fourth]': {
dataRoute: `/_next/data/${next.buildId}/catchall-explicit/[third]/[fourth].json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall-explicit/[...slug]',
},
'/catchall-optional': {
dataRoute: `/_next/data/${next.buildId}/catchall-optional.json`,
initialRevalidateSeconds: false,
srcRoute: '/catchall-optional/[[...slug]]',
},
'/catchall-optional/value': {
dataRoute: `/_next/data/${next.buildId}/catchall-optional/value.json`,
initialRevalidateSeconds: false,
srcRoute: '/catchall-optional/[[...slug]]',
},
'/large-page-data': {
dataRoute: `/_next/data/${next.buildId}/large-page-data.json`,
initialRevalidateSeconds: false,
srcRoute: null,
},
'/another': {
dataRoute: `/_next/data/${next.buildId}/another.json`,
initialRevalidateSeconds: 1,
srcRoute: null,
},
'/preview': {
dataRoute: `/_next/data/${next.buildId}/preview.json`,
initialRevalidateSeconds: false,
srcRoute: null,
},
'/api-docs/first': {
dataRoute: `/_next/data/${next.buildId}/api-docs/first.json`,
initialRevalidateSeconds: false,
srcRoute: '/api-docs/[...slug]',
},
'/blocking-fallback-once/404-on-manual-revalidate': {
dataRoute: `/_next/data/${next.buildId}/blocking-fallback-once/404-on-manual-revalidate.json`,
initialRevalidateSeconds: false,
srcRoute: '/blocking-fallback-once/[slug]',
},
'/blocking-fallback-some/a': {
dataRoute: `/_next/data/${next.buildId}/blocking-fallback-some/a.json`,
initialRevalidateSeconds: 1,
srcRoute: '/blocking-fallback-some/[slug]',
},
'/blocking-fallback-some/b': {
dataRoute: `/_next/data/${next.buildId}/blocking-fallback-some/b.json`,
initialRevalidateSeconds: 1,
srcRoute: '/blocking-fallback-some/[slug]',
},
'/blocking-fallback/lots-of-data': {
dataRoute: `/_next/data/${next.buildId}/blocking-fallback/lots-of-data.json`,
initialRevalidateSeconds: false,
srcRoute: '/blocking-fallback/[slug]',
},
'/blocking-fallback/test-errors-1': {
dataRoute: `/_next/data/${next.buildId}/blocking-fallback/test-errors-1.json`,
initialRevalidateSeconds: 1,
srcRoute: '/blocking-fallback/[slug]',
},
'/blog': {
dataRoute: `/_next/data/${next.buildId}/blog.json`,
initialRevalidateSeconds: 10,
srcRoute: null,
},
'/default-revalidate': {
dataRoute: `/_next/data/${next.buildId}/default-revalidate.json`,
initialRevalidateSeconds: false,
srcRoute: null,
},
'/dynamic/[first]': {
dataRoute: `/_next/data/${next.buildId}/dynamic/[first].json`,
initialRevalidateSeconds: false,
srcRoute: '/dynamic/[slug]',
},
'/dynamic/[second]': {
dataRoute: `/_next/data/${next.buildId}/dynamic/[second].json`,
initialRevalidateSeconds: false,
srcRoute: '/dynamic/[slug]',
},
// TODO: investigate index/index
// '/index': {
// dataRoute: `/_next/data/${next.buildId}/index/index.json`,
// initialRevalidateSeconds: false,
// srcRoute: null,
// },
'/lang/de/about': {
dataRoute: `/_next/data/${next.buildId}/lang/de/about.json`,
initialRevalidateSeconds: false,
srcRoute: '/lang/[lang]/about',
},
'/lang/en/about': {
dataRoute: `/_next/data/${next.buildId}/lang/en/about.json`,
initialRevalidateSeconds: false,
srcRoute: '/lang/[lang]/about',
},
'/lang/es/about': {
dataRoute: `/_next/data/${next.buildId}/lang/es/about.json`,
initialRevalidateSeconds: false,
srcRoute: '/lang/[lang]/about',
},
'/lang/fr/about': {
dataRoute: `/_next/data/${next.buildId}/lang/fr/about.json`,
initialRevalidateSeconds: false,
srcRoute: '/lang/[lang]/about',
},
'/something': {
dataRoute: `/_next/data/${next.buildId}/something.json`,
initialRevalidateSeconds: false,
srcRoute: null,
},
'/catchall/another/value': {
dataRoute: `/_next/data/${next.buildId}/catchall/another/value.json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall/[...slug]',
},
'/catchall/first': {
dataRoute: `/_next/data/${next.buildId}/catchall/first.json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall/[...slug]',
},
'/catchall/second': {
dataRoute: `/_next/data/${next.buildId}/catchall/second.json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall/[...slug]',
},
'/catchall/hello/another': {
dataRoute: `/_next/data/${next.buildId}/catchall/hello/another.json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall/[...slug]',
},
})
const navigateTest = (isDev = false) => { const navigateTest = (isDev = false) => {
it('should navigate between pages successfully', async () => { it('should navigate between pages successfully', async () => {
const toBuild = [ const toBuild = [
...@@ -1290,303 +1091,263 @@ describe('Prerender', () => { ...@@ -1290,303 +1091,263 @@ describe('Prerender', () => {
) )
for (const route of dataRoutes) { for (const route of dataRoutes) {
route.dataRouteRegex = normalizeRegEx(route.dataRouteRegex) normalizeRouteRegExes(route)
} }
expect(dataRoutes).toEqual([ expect(dataRoutes).toEqual(
{ [
dataRouteRegex: normalizeRegEx( {
`^\\/_next\\/data\\/${escapeRegex(next.buildId)}\\/index.json$` dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
),
page: '/',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/another.json$` )}\\/index.json$`,
), page: '/',
page: '/another', },
}, {
{ dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/api\\-docs\\/(.+?)\\.json$` )}\\/another.json$`,
), page: '/another',
namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId
)}/api\\-docs/(?<nxtPslug>.+?)\\.json$`,
page: '/api-docs/[...slug]',
routeKeys: {
nxtPslug: 'nxtPslug',
}, },
}, {
{ dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/bad-gssp.json$` )}\\/api\\-docs\\/(.+?)\\.json$`,
), namedDataRouteRegex: `^/_next/data/${escapeRegex(
page: '/bad-gssp',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/bad-ssr.json$` )}/api\\-docs/(?<nxtPslug>.+?)\\.json$`,
), page: '/api-docs/[...slug]',
page: '/bad-ssr', routeKeys: {
}, nxtPslug: 'nxtPslug',
{ },
dataRouteRegex: normalizeRegEx( },
`^\\/_next\\/data\\/${escapeRegex( {
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/blocking\\-fallback\\/([^\\/]+?)\\.json$` )}\\/bad-gssp.json$`,
), page: '/bad-gssp',
namedDataRouteRegex: `^/_next/data/${escapeRegex( },
next.buildId {
)}/blocking\\-fallback/(?<nxtPslug>[^/]+?)\\.json$`, dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
page: '/blocking-fallback/[slug]',
routeKeys: { nxtPslug: 'nxtPslug' },
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/blocking\\-fallback\\-once\\/([^\\/]+?)\\.json$` )}\\/bad-ssr.json$`,
), page: '/bad-ssr',
namedDataRouteRegex: `^/_next/data/${escapeRegex( },
next.buildId {
)}/blocking\\-fallback\\-once/(?<nxtPslug>[^/]+?)\\.json$`, dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
page: '/blocking-fallback-once/[slug]',
routeKeys: { nxtPslug: 'nxtPslug' },
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/blocking\\-fallback\\-some\\/([^\\/]+?)\\.json$` )}\\/blocking\\-fallback\\/([^\\/]+?)\\.json$`,
), namedDataRouteRegex: `^/_next/data/${escapeRegex(
namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId
)}/blocking\\-fallback\\-some/(?<nxtPslug>[^/]+?)\\.json$`,
page: '/blocking-fallback-some/[slug]',
routeKeys: { nxtPslug: 'nxtPslug' },
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(next.buildId)}\\/blog.json$`
),
page: '/blog',
},
{
namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId
)}/blog/(?<nxtPpost>[^/]+?)\\.json$`,
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/blog\\/([^\\/]+?)\\.json$` )}/blocking\\-fallback/(?<nxtPslug>[^/]+?)\\.json$`,
), page: '/blocking-fallback/[slug]',
page: '/blog/[post]', routeKeys: { nxtPslug: 'nxtPslug' },
routeKeys: {
nxtPpost: 'nxtPpost',
}, },
}, {
{ dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId
)}/blog/(?<nxtPpost>[^/]+?)/(?<nxtPcomment>[^/]+?)\\.json$`,
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/blog\\/([^\\/]+?)\\/([^\\/]+?)\\.json$` )}\\/blocking\\-fallback\\-once\\/([^\\/]+?)\\.json$`,
), namedDataRouteRegex: `^/_next/data/${escapeRegex(
page: '/blog/[post]/[comment]', next.buildId
routeKeys: { )}/blocking\\-fallback\\-once/(?<nxtPslug>[^/]+?)\\.json$`,
nxtPpost: 'nxtPpost', page: '/blocking-fallback-once/[slug]',
nxtPcomment: 'nxtPcomment', routeKeys: { nxtPslug: 'nxtPslug' },
}, },
}, {
{ dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId
)}/catchall/(?<nxtPslug>.+?)\\.json$`,
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/catchall\\/(.+?)\\.json$` )}\\/blocking\\-fallback\\-some\\/([^\\/]+?)\\.json$`,
), namedDataRouteRegex: `^/_next/data/${escapeRegex(
page: '/catchall/[...slug]', next.buildId
routeKeys: { )}/blocking\\-fallback\\-some/(?<nxtPslug>[^/]+?)\\.json$`,
nxtPslug: 'nxtPslug', page: '/blocking-fallback-some/[slug]',
routeKeys: { nxtPslug: 'nxtPslug' },
}, },
}, {
{ dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId
)}/catchall\\-explicit/(?<nxtPslug>.+?)\\.json$`,
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/catchall\\-explicit\\/(.+?)\\.json$` )}\\/blog.json$`,
), page: '/blog',
page: '/catchall-explicit/[...slug]',
routeKeys: {
nxtPslug: 'nxtPslug',
}, },
}, {
{ namedDataRouteRegex: `^/_next/data/${escapeRegex(
namedDataRouteRegex: `^/_next/data/${escapeRegex( next.buildId
next.buildId )}/blog/(?<nxtPpost>[^/]+?)\\.json$`,
)}/catchall\\-optional(?:/(?<nxtPslug>.+?))?\\.json$`, dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/catchall\\-optional(?:\\/(.+?))?\\.json$` )}\\/blog\\/([^\\/]+?)\\.json$`,
), page: '/blog/[post]',
page: '/catchall-optional/[[...slug]]', routeKeys: {
routeKeys: { nxtPpost: 'nxtPpost',
nxtPslug: 'nxtPslug', },
}, },
}, {
{ namedDataRouteRegex: `^/_next/data/${escapeRegex(
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/default-revalidate.json$` )}/blog/(?<nxtPpost>[^/]+?)/(?<nxtPcomment>[^/]+?)\\.json$`,
), dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
page: '/default-revalidate',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/dynamic\\/([^\\/]+?)\\.json$` )}\\/blog\\/([^\\/]+?)\\/([^\\/]+?)\\.json$`,
), page: '/blog/[post]/[comment]',
namedDataRouteRegex: `^/_next/data/${escapeRegex( routeKeys: {
next.buildId nxtPpost: 'nxtPpost',
)}/dynamic/(?<nxtPslug>[^/]+?)\\.json$`, nxtPcomment: 'nxtPcomment',
page: '/dynamic/[slug]', },
routeKeys: {
nxtPslug: 'nxtPslug',
}, },
}, {
{ namedDataRouteRegex: `^/_next/data/${escapeRegex(
dataRouteRegex: normalizeRegEx( next.buildId
`^\\/_next\\/data\\/${escapeRegex( )}/catchall/(?<nxtPslug>.+?)\\.json$`,
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/fallback\\-only\\/([^\\/]+?)\\.json$` )}\\/catchall\\/(.+?)\\.json$`,
), page: '/catchall/[...slug]',
namedDataRouteRegex: `^/_next/data/${escapeRegex( routeKeys: {
next.buildId nxtPslug: 'nxtPslug',
)}/fallback\\-only/(?<nxtPslug>[^/]+?)\\.json$`, },
page: '/fallback-only/[slug]',
routeKeys: {
nxtPslug: 'nxtPslug',
}, },
}, {
// TODO: investigate index/index namedDataRouteRegex: `^/_next/data/${escapeRegex(
// { next.buildId
// dataRouteRegex: normalizeRegEx( )}/catchall\\-explicit/(?<nxtPslug>.+?)\\.json$`,
// `^\\/_next\\/data\\/${escapeRegex( dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
// next.buildId
// )}\\/index\\/index.json$`
// ),
// page: '/index',
// },
{
namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId
)}/lang/(?<nxtPlang>[^/]+?)/about\\.json$`,
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/lang\\/([^\\/]+?)\\/about\\.json$` )}\\/catchall\\-explicit\\/(.+?)\\.json$`,
), page: '/catchall-explicit/[...slug]',
page: '/lang/[lang]/about', routeKeys: {
routeKeys: { nxtPslug: 'nxtPslug',
nxtPlang: 'nxtPlang', },
}, },
}, {
{ namedDataRouteRegex: `^/_next/data/${escapeRegex(
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/large-page-data.json$`,
page: '/large-page-data',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/large-page-data-ssr.json$`,
page: '/large-page-data-ssr',
},
{
namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId
)}/non\\-json/(?<nxtPp>[^/]+?)\\.json$`,
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/non\\-json\\/([^\\/]+?)\\.json$` )}/catchall\\-optional(?:/(?<nxtPslug>.+?))?\\.json$`,
), dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
page: '/non-json/[p]', next.buildId
routeKeys: { )}\\/catchall\\-optional(?:\\/(.+?))?\\.json$`,
nxtPp: 'nxtPp', page: '/catchall-optional/[[...slug]]',
routeKeys: {
nxtPslug: 'nxtPslug',
},
}, },
}, {
{ dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId
)}/non\\-json\\-blocking/(?<nxtPp>[^/]+?)\\.json$`,
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/non\\-json\\-blocking\\/([^\\/]+?)\\.json$` )}\\/default-revalidate.json$`,
), page: '/default-revalidate',
page: '/non-json-blocking/[p]',
routeKeys: {
nxtPp: 'nxtPp',
}, },
}, {
{ dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/preview.json$` )}\\/dynamic\\/([^\\/]+?)\\.json$`,
), namedDataRouteRegex: `^/_next/data/${escapeRegex(
page: '/preview',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/something.json$` )}/dynamic/(?<nxtPslug>[^/]+?)\\.json$`,
), page: '/dynamic/[slug]',
page: '/something', routeKeys: {
}, nxtPslug: 'nxtPslug',
{ },
dataRouteRegex: normalizeRegEx( },
`^\\/_next\\/data\\/${escapeRegex(next.buildId)}\\/ssr.json$` {
), dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
page: '/ssr', next.buildId
}, )}\\/fallback\\-only\\/([^\\/]+?)\\.json$`,
{ namedDataRouteRegex: `^/_next/data/${escapeRegex(
namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId
)}/user/(?<nxtPuser>[^/]+?)/profile\\.json$`,
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId next.buildId
)}\\/user\\/([^\\/]+?)\\/profile\\.json$` )}/fallback\\-only/(?<nxtPslug>[^/]+?)\\.json$`,
), page: '/fallback-only/[slug]',
page: '/user/[user]/profile', routeKeys: {
routeKeys: { nxtPslug: 'nxtPslug',
nxtPuser: 'nxtPuser', },
}, },
}, // TODO: investigate index/index
]) // {
// dataRouteRegex: (
// `^\\/_next\\/data\\/${escapeRegex(
// next.buildId
// )}\\/index\\/index.json$`
// ),
// page: '/index',
// },
{
namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId
)}/lang/(?<nxtPlang>[^/]+?)/about\\.json$`,
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/lang\\/([^\\/]+?)\\/about\\.json$`,
page: '/lang/[lang]/about',
routeKeys: {
nxtPlang: 'nxtPlang',
},
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/large-page-data.json$`,
page: '/large-page-data',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/large-page-data-ssr.json$`,
page: '/large-page-data-ssr',
},
{
namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId
)}/non\\-json/(?<nxtPp>[^/]+?)\\.json$`,
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/non\\-json\\/([^\\/]+?)\\.json$`,
page: '/non-json/[p]',
routeKeys: {
nxtPp: 'nxtPp',
},
},
{
namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId
)}/non\\-json\\-blocking/(?<nxtPp>[^/]+?)\\.json$`,
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/non\\-json\\-blocking\\/([^\\/]+?)\\.json$`,
page: '/non-json-blocking/[p]',
routeKeys: {
nxtPp: 'nxtPp',
},
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/preview.json$`,
page: '/preview',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/something.json$`,
page: '/something',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/ssr.json$`,
page: '/ssr',
},
{
namedDataRouteRegex: `^/_next/data/${escapeRegex(
next.buildId
)}/user/(?<nxtPuser>[^/]+?)/profile\\.json$`,
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/user\\/([^\\/]+?)\\/profile\\.json$`,
page: '/user/[user]/profile',
routeKeys: {
nxtPuser: 'nxtPuser',
},
},
].map((item) => normalizeRouteRegExes(item))
)
}) })
it('outputs a prerender-manifest correctly', async () => { it('outputs a prerender-manifest correctly', async () => {
...@@ -1597,162 +1358,315 @@ describe('Prerender', () => { ...@@ -1597,162 +1358,315 @@ describe('Prerender', () => {
Object.keys(manifest.dynamicRoutes).forEach((key) => { Object.keys(manifest.dynamicRoutes).forEach((key) => {
const item = manifest.dynamicRoutes[key] const item = manifest.dynamicRoutes[key]
normalizeRouteRegExes(item)
if (item.dataRouteRegex) {
item.dataRouteRegex = normalizeRegEx(item.dataRouteRegex)
}
if (item.routeRegex) {
item.routeRegex = normalizeRegEx(item.routeRegex)
}
}) })
expect(manifest.version).toBe(4) const expectedDynamicRoutes = {
expect(manifest.routes).toEqual(expectedManifestRoutes())
expect(manifest.dynamicRoutes).toEqual({
'/api-docs/[...slug]': { '/api-docs/[...slug]': {
dataRoute: `/_next/data/${next.buildId}/api-docs/[...slug].json`, dataRoute: `/_next/data/${next.buildId}/api-docs/[...slug].json`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/api\\-docs\\/(.+?)\\.json$`,
`^\\/_next\\/data\\/${escapedBuildId}\\/api\\-docs\\/(.+?)\\.json$`
),
fallback: '/api-docs/[...slug].html', fallback: '/api-docs/[...slug].html',
routeRegex: normalizeRegEx(`^\\/api\\-docs\\/(.+?)(?:\\/)?$`), routeRegex: `^\\/api\\-docs\\/(.+?)(?:\\/)?$`,
}, },
'/blocking-fallback-once/[slug]': { '/blocking-fallback-once/[slug]': {
dataRoute: `/_next/data/${next.buildId}/blocking-fallback-once/[slug].json`, dataRoute: `/_next/data/${next.buildId}/blocking-fallback-once/[slug].json`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/blocking\\-fallback\\-once\\/([^\\/]+?)\\.json$`,
`^\\/_next\\/data\\/${escapedBuildId}\\/blocking\\-fallback\\-once\\/([^\\/]+?)\\.json$`
),
fallback: null, fallback: null,
routeRegex: normalizeRegEx( routeRegex:
'^\\/blocking\\-fallback\\-once\\/([^\\/]+?)(?:\\/)?$' '^\\/blocking\\-fallback\\-once\\/([^\\/]+?)(?:\\/)?$',
),
}, },
'/blocking-fallback-some/[slug]': { '/blocking-fallback-some/[slug]': {
dataRoute: `/_next/data/${next.buildId}/blocking-fallback-some/[slug].json`, dataRoute: `/_next/data/${next.buildId}/blocking-fallback-some/[slug].json`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/blocking\\-fallback\\-some\\/([^\\/]+?)\\.json$`,
`^\\/_next\\/data\\/${escapedBuildId}\\/blocking\\-fallback\\-some\\/([^\\/]+?)\\.json$`
),
fallback: null, fallback: null,
routeRegex: normalizeRegEx( routeRegex:
'^\\/blocking\\-fallback\\-some\\/([^\\/]+?)(?:\\/)?$' '^\\/blocking\\-fallback\\-some\\/([^\\/]+?)(?:\\/)?$',
),
}, },
'/blocking-fallback/[slug]': { '/blocking-fallback/[slug]': {
dataRoute: `/_next/data/${next.buildId}/blocking-fallback/[slug].json`, dataRoute: `/_next/data/${next.buildId}/blocking-fallback/[slug].json`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/blocking\\-fallback\\/([^\\/]+?)\\.json$`,
`^\\/_next\\/data\\/${escapedBuildId}\\/blocking\\-fallback\\/([^\\/]+?)\\.json$`
),
fallback: null, fallback: null,
routeRegex: normalizeRegEx( routeRegex: '^\\/blocking\\-fallback\\/([^\\/]+?)(?:\\/)?$',
'^\\/blocking\\-fallback\\/([^\\/]+?)(?:\\/)?$'
),
}, },
'/blog/[post]': { '/blog/[post]': {
fallback: '/blog/[post].html', fallback: '/blog/[post].html',
dataRoute: `/_next/data/${next.buildId}/blog/[post].json`, dataRoute: `/_next/data/${next.buildId}/blog/[post].json`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/blog\\/([^\\/]+?)\\.json$`,
`^\\/_next\\/data\\/${escapedBuildId}\\/blog\\/([^\\/]+?)\\.json$` routeRegex: '^\\/blog\\/([^\\/]+?)(?:\\/)?$',
),
routeRegex: normalizeRegEx('^\\/blog\\/([^\\/]+?)(?:\\/)?$'),
}, },
'/blog/[post]/[comment]': { '/blog/[post]/[comment]': {
fallback: '/blog/[post]/[comment].html', fallback: '/blog/[post]/[comment].html',
dataRoute: `/_next/data/${next.buildId}/blog/[post]/[comment].json`, dataRoute: `/_next/data/${next.buildId}/blog/[post]/[comment].json`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/blog\\/([^\\/]+?)\\/([^\\/]+?)\\.json$`,
`^\\/_next\\/data\\/${escapedBuildId}\\/blog\\/([^\\/]+?)\\/([^\\/]+?)\\.json$` routeRegex: '^\\/blog\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$',
),
routeRegex: normalizeRegEx(
'^\\/blog\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$'
),
}, },
'/dynamic/[slug]': { '/dynamic/[slug]': {
dataRoute: `/_next/data/${next.buildId}/dynamic/[slug].json`, dataRoute: `/_next/data/${next.buildId}/dynamic/[slug].json`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/dynamic\\/([^\\/]+?)\\.json$`,
`^\\/_next\\/data\\/${escapedBuildId}\\/dynamic\\/([^\\/]+?)\\.json$`
),
fallback: false, fallback: false,
routeRegex: normalizeRegEx(`^\\/dynamic\\/([^\\/]+?)(?:\\/)?$`), routeRegex: `^\\/dynamic\\/([^\\/]+?)(?:\\/)?$`,
}, },
'/fallback-only/[slug]': { '/fallback-only/[slug]': {
dataRoute: `/_next/data/${next.buildId}/fallback-only/[slug].json`, dataRoute: `/_next/data/${next.buildId}/fallback-only/[slug].json`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/fallback\\-only\\/([^\\/]+?)\\.json$`,
`^\\/_next\\/data\\/${escapedBuildId}\\/fallback\\-only\\/([^\\/]+?)\\.json$`
),
fallback: '/fallback-only/[slug].html', fallback: '/fallback-only/[slug].html',
routeRegex: normalizeRegEx( routeRegex: '^\\/fallback\\-only\\/([^\\/]+?)(?:\\/)?$',
'^\\/fallback\\-only\\/([^\\/]+?)(?:\\/)?$'
),
}, },
'/lang/[lang]/about': { '/lang/[lang]/about': {
dataRoute: `/_next/data/${next.buildId}/lang/[lang]/about.json`, dataRoute: `/_next/data/${next.buildId}/lang/[lang]/about.json`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/lang\\/([^\\/]+?)\\/about\\.json$`,
`^\\/_next\\/data\\/${escapedBuildId}\\/lang\\/([^\\/]+?)\\/about\\.json$`
),
fallback: false, fallback: false,
routeRegex: normalizeRegEx( routeRegex: '^\\/lang\\/([^\\/]+?)\\/about(?:\\/)?$',
'^\\/lang\\/([^\\/]+?)\\/about(?:\\/)?$'
),
}, },
'/non-json-blocking/[p]': { '/non-json-blocking/[p]': {
dataRoute: `/_next/data/${next.buildId}/non-json-blocking/[p].json`, dataRoute: `/_next/data/${next.buildId}/non-json-blocking/[p].json`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/non\\-json\\-blocking\\/([^\\/]+?)\\.json$`,
`^\\/_next\\/data\\/${escapedBuildId}\\/non\\-json\\-blocking\\/([^\\/]+?)\\.json$`
),
fallback: null, fallback: null,
routeRegex: normalizeRegEx( routeRegex: '^\\/non\\-json\\-blocking\\/([^\\/]+?)(?:\\/)?$',
'^\\/non\\-json\\-blocking\\/([^\\/]+?)(?:\\/)?$'
),
}, },
'/non-json/[p]': { '/non-json/[p]': {
dataRoute: `/_next/data/${next.buildId}/non-json/[p].json`, dataRoute: `/_next/data/${next.buildId}/non-json/[p].json`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/non\\-json\\/([^\\/]+?)\\.json$`,
`^\\/_next\\/data\\/${escapedBuildId}\\/non\\-json\\/([^\\/]+?)\\.json$`
),
fallback: '/non-json/[p].html', fallback: '/non-json/[p].html',
routeRegex: normalizeRegEx( routeRegex: '^\\/non\\-json\\/([^\\/]+?)(?:\\/)?$',
'^\\/non\\-json\\/([^\\/]+?)(?:\\/)?$'
),
}, },
'/user/[user]/profile': { '/user/[user]/profile': {
fallback: '/user/[user]/profile.html', fallback: '/user/[user]/profile.html',
dataRoute: `/_next/data/${next.buildId}/user/[user]/profile.json`, dataRoute: `/_next/data/${next.buildId}/user/[user]/profile.json`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/user\\/([^\\/]+?)\\/profile\\.json$`,
`^\\/_next\\/data\\/${escapedBuildId}\\/user\\/([^\\/]+?)\\/profile\\.json$` routeRegex: `^\\/user\\/([^\\/]+?)\\/profile(?:\\/)?$`,
),
routeRegex: normalizeRegEx(
`^\\/user\\/([^\\/]+?)\\/profile(?:\\/)?$`
),
}, },
'/catchall/[...slug]': { '/catchall/[...slug]': {
fallback: '/catchall/[...slug].html', fallback: '/catchall/[...slug].html',
routeRegex: normalizeRegEx('^\\/catchall\\/(.+?)(?:\\/)?$'), routeRegex: '^\\/catchall\\/(.+?)(?:\\/)?$',
dataRoute: `/_next/data/${next.buildId}/catchall/[...slug].json`, dataRoute: `/_next/data/${next.buildId}/catchall/[...slug].json`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/catchall\\/(.+?)\\.json$`,
`^\\/_next\\/data\\/${escapedBuildId}\\/catchall\\/(.+?)\\.json$`
),
}, },
'/catchall-optional/[[...slug]]': { '/catchall-optional/[[...slug]]': {
dataRoute: `/_next/data/${next.buildId}/catchall-optional/[[...slug]].json`, dataRoute: `/_next/data/${next.buildId}/catchall-optional/[[...slug]].json`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/catchall\\-optional(?:\\/(.+?))?\\.json$`,
`^\\/_next\\/data\\/${escapedBuildId}\\/catchall\\-optional(?:\\/(.+?))?\\.json$`
),
fallback: false, fallback: false,
routeRegex: normalizeRegEx( routeRegex: '^\\/catchall\\-optional(?:\\/(.+?))?(?:\\/)?$',
'^\\/catchall\\-optional(?:\\/(.+?))?(?:\\/)?$'
),
}, },
'/catchall-explicit/[...slug]': { '/catchall-explicit/[...slug]': {
dataRoute: `/_next/data/${next.buildId}/catchall-explicit/[...slug].json`, dataRoute: `/_next/data/${next.buildId}/catchall-explicit/[...slug].json`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/catchall\\-explicit\\/(.+?)\\.json$`,
`^\\/_next\\/data\\/${escapedBuildId}\\/catchall\\-explicit\\/(.+?)\\.json$`
),
fallback: false, fallback: false,
routeRegex: normalizeRegEx( routeRegex: '^\\/catchall\\-explicit\\/(.+?)(?:\\/)?$',
'^\\/catchall\\-explicit\\/(.+?)(?:\\/)?$' },
), }
Object.keys(expectedDynamicRoutes).forEach((key) => {
const item = expectedDynamicRoutes[key]
normalizeRouteRegExes(item)
})
const expectedManifestRoutes = {
'/': {
dataRoute: `/_next/data/${next.buildId}/index.json`,
initialRevalidateSeconds: 2,
srcRoute: null,
},
'/blog/[post3]': {
dataRoute: `/_next/data/${next.buildId}/blog/[post3].json`,
initialRevalidateSeconds: 10,
srcRoute: '/blog/[post]',
},
'/blog/post-1': {
dataRoute: `/_next/data/${next.buildId}/blog/post-1.json`,
initialRevalidateSeconds: 10,
srcRoute: '/blog/[post]',
},
'/blog/post-2': {
dataRoute: `/_next/data/${next.buildId}/blog/post-2.json`,
initialRevalidateSeconds: 10,
srcRoute: '/blog/[post]',
},
'/blog/post-4': {
dataRoute: `/_next/data/${next.buildId}/blog/post-4.json`,
initialRevalidateSeconds: 10,
srcRoute: '/blog/[post]',
},
'/blog/post-1/comment-1': {
dataRoute: `/_next/data/${next.buildId}/blog/post-1/comment-1.json`,
initialRevalidateSeconds: 2,
srcRoute: '/blog/[post]/[comment]',
},
'/blog/post-2/comment-2': {
dataRoute: `/_next/data/${next.buildId}/blog/post-2/comment-2.json`,
initialRevalidateSeconds: 2,
srcRoute: '/blog/[post]/[comment]',
},
'/blog/post.1': {
dataRoute: `/_next/data/${next.buildId}/blog/post.1.json`,
initialRevalidateSeconds: 10,
srcRoute: '/blog/[post]',
}, },
'/catchall-explicit/another/value': {
dataRoute: `/_next/data/${next.buildId}/catchall-explicit/another/value.json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall-explicit/[...slug]',
},
'/catchall-explicit/first': {
dataRoute: `/_next/data/${next.buildId}/catchall-explicit/first.json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall-explicit/[...slug]',
},
'/catchall-explicit/hello/another': {
dataRoute: `/_next/data/${next.buildId}/catchall-explicit/hello/another.json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall-explicit/[...slug]',
},
'/catchall-explicit/second': {
dataRoute: `/_next/data/${next.buildId}/catchall-explicit/second.json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall-explicit/[...slug]',
},
'/catchall-explicit/[first]/[second]': {
dataRoute: `/_next/data/${next.buildId}/catchall-explicit/[first]/[second].json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall-explicit/[...slug]',
},
'/catchall-explicit/[third]/[fourth]': {
dataRoute: `/_next/data/${next.buildId}/catchall-explicit/[third]/[fourth].json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall-explicit/[...slug]',
},
'/catchall-optional': {
dataRoute: `/_next/data/${next.buildId}/catchall-optional.json`,
initialRevalidateSeconds: false,
srcRoute: '/catchall-optional/[[...slug]]',
},
'/catchall-optional/value': {
dataRoute: `/_next/data/${next.buildId}/catchall-optional/value.json`,
initialRevalidateSeconds: false,
srcRoute: '/catchall-optional/[[...slug]]',
},
'/large-page-data': {
dataRoute: `/_next/data/${next.buildId}/large-page-data.json`,
initialRevalidateSeconds: false,
srcRoute: null,
},
'/another': {
dataRoute: `/_next/data/${next.buildId}/another.json`,
initialRevalidateSeconds: 1,
srcRoute: null,
},
'/preview': {
dataRoute: `/_next/data/${next.buildId}/preview.json`,
initialRevalidateSeconds: false,
srcRoute: null,
},
'/api-docs/first': {
dataRoute: `/_next/data/${next.buildId}/api-docs/first.json`,
initialRevalidateSeconds: false,
srcRoute: '/api-docs/[...slug]',
},
'/blocking-fallback-once/404-on-manual-revalidate': {
dataRoute: `/_next/data/${next.buildId}/blocking-fallback-once/404-on-manual-revalidate.json`,
initialRevalidateSeconds: false,
srcRoute: '/blocking-fallback-once/[slug]',
},
'/blocking-fallback-some/a': {
dataRoute: `/_next/data/${next.buildId}/blocking-fallback-some/a.json`,
initialRevalidateSeconds: 1,
srcRoute: '/blocking-fallback-some/[slug]',
},
'/blocking-fallback-some/b': {
dataRoute: `/_next/data/${next.buildId}/blocking-fallback-some/b.json`,
initialRevalidateSeconds: 1,
srcRoute: '/blocking-fallback-some/[slug]',
},
'/blocking-fallback/lots-of-data': {
dataRoute: `/_next/data/${next.buildId}/blocking-fallback/lots-of-data.json`,
initialRevalidateSeconds: false,
srcRoute: '/blocking-fallback/[slug]',
},
'/blocking-fallback/test-errors-1': {
dataRoute: `/_next/data/${next.buildId}/blocking-fallback/test-errors-1.json`,
initialRevalidateSeconds: 1,
srcRoute: '/blocking-fallback/[slug]',
},
'/blog': {
dataRoute: `/_next/data/${next.buildId}/blog.json`,
initialRevalidateSeconds: 10,
srcRoute: null,
},
'/default-revalidate': {
dataRoute: `/_next/data/${next.buildId}/default-revalidate.json`,
initialRevalidateSeconds: false,
srcRoute: null,
},
'/dynamic/[first]': {
dataRoute: `/_next/data/${next.buildId}/dynamic/[first].json`,
initialRevalidateSeconds: false,
srcRoute: '/dynamic/[slug]',
},
'/dynamic/[second]': {
dataRoute: `/_next/data/${next.buildId}/dynamic/[second].json`,
initialRevalidateSeconds: false,
srcRoute: '/dynamic/[slug]',
},
// TODO: investigate index/index
// '/index': {
// dataRoute: `/_next/data/${next.buildId}/index/index.json`,
// initialRevalidateSeconds: false,
// srcRoute: null,
// },
'/lang/de/about': {
dataRoute: `/_next/data/${next.buildId}/lang/de/about.json`,
initialRevalidateSeconds: false,
srcRoute: '/lang/[lang]/about',
},
'/lang/en/about': {
dataRoute: `/_next/data/${next.buildId}/lang/en/about.json`,
initialRevalidateSeconds: false,
srcRoute: '/lang/[lang]/about',
},
'/lang/es/about': {
dataRoute: `/_next/data/${next.buildId}/lang/es/about.json`,
initialRevalidateSeconds: false,
srcRoute: '/lang/[lang]/about',
},
'/lang/fr/about': {
dataRoute: `/_next/data/${next.buildId}/lang/fr/about.json`,
initialRevalidateSeconds: false,
srcRoute: '/lang/[lang]/about',
},
'/something': {
dataRoute: `/_next/data/${next.buildId}/something.json`,
initialRevalidateSeconds: false,
srcRoute: null,
},
'/catchall/another/value': {
dataRoute: `/_next/data/${next.buildId}/catchall/another/value.json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall/[...slug]',
},
'/catchall/first': {
dataRoute: `/_next/data/${next.buildId}/catchall/first.json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall/[...slug]',
},
'/catchall/second': {
dataRoute: `/_next/data/${next.buildId}/catchall/second.json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall/[...slug]',
},
'/catchall/hello/another': {
dataRoute: `/_next/data/${next.buildId}/catchall/hello/another.json`,
initialRevalidateSeconds: 1,
srcRoute: '/catchall/[...slug]',
},
}
Object.keys(expectedManifestRoutes).forEach((key) => {
const item = expectedManifestRoutes[key]
normalizeRouteRegExes(item)
}) })
expect(manifest.version).toBe(4)
expect(manifest.routes).toEqual(expectedManifestRoutes)
expect(manifest.dynamicRoutes).toEqual(expectedDynamicRoutes)
}) })
it('outputs prerendered files correctly', async () => { it('outputs prerendered files correctly', async () => {
......
...@@ -20,9 +20,9 @@ import { ...@@ -20,9 +20,9 @@ import {
renderViaHTTP, renderViaHTTP,
getBrowserBodyText, getBrowserBodyText,
waitFor, waitFor,
normalizeRegEx,
hasRedbox, hasRedbox,
check, check,
normalizeRouteRegExes,
} from 'next-test-utils' } from 'next-test-utils'
let appDir = join(__dirname, '..') let appDir = join(__dirname, '..')
...@@ -1482,17 +1482,16 @@ const runTests = (isDev = false) => { ...@@ -1482,17 +1482,16 @@ const runTests = (isDev = false) => {
) )
for (const route of [ for (const route of [
...manifest.staticRoutes,
...manifest.dynamicRoutes, ...manifest.dynamicRoutes,
...manifest.rewrites.beforeFiles, ...manifest.rewrites.beforeFiles,
...manifest.rewrites.afterFiles, ...manifest.rewrites.afterFiles,
...manifest.rewrites.fallback, ...manifest.rewrites.fallback,
...manifest.redirects, ...manifest.redirects,
...manifest.headers, ...manifest.headers,
...manifest.dataRoutes,
]) { ]) {
route.regex = normalizeRegEx(route.regex) normalizeRouteRegExes(route)
}
for (const route of manifest.dataRoutes) {
route.dataRouteRegex = normalizeRegEx(route.dataRouteRegex)
} }
expect(manifest).toEqual({ expect(manifest).toEqual({
...@@ -1502,11 +1501,9 @@ const runTests = (isDev = false) => { ...@@ -1502,11 +1501,9 @@ const runTests = (isDev = false) => {
basePath: '', basePath: '',
dataRoutes: [ dataRoutes: [
{ {
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^/_next/data/${escapeRegex(
`^/_next/data/${escapeRegex( buildId
buildId )}/blog\\-catchall/(.+?)\\.json$`,
)}/blog\\-catchall/(.+?)\\.json$`
),
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId buildId
)}/blog\\-catchall/(?<nxtPslug>.+?)\\.json$`, )}/blog\\-catchall/(?<nxtPslug>.+?)\\.json$`,
...@@ -1527,13 +1524,11 @@ const runTests = (isDev = false) => { ...@@ -1527,13 +1524,11 @@ const runTests = (isDev = false) => {
nxtPslug: 'nxtPslug', nxtPslug: 'nxtPslug',
}, },
}, },
], ].map((item) => normalizeRouteRegExes(item)),
redirects: [ redirects: [
{ {
destination: '/:path+', destination: '/:path+',
regex: normalizeRegEx( regex: '^(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))\\/$',
'^(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))\\/$'
),
source: '/:path+/', source: '/:path+/',
statusCode: 308, statusCode: 308,
internal: true, internal: true,
...@@ -1547,9 +1542,7 @@ const runTests = (isDev = false) => { ...@@ -1547,9 +1542,7 @@ const runTests = (isDev = false) => {
value: '(?<myHeader>.*)', value: '(?<myHeader>.*)',
}, },
], ],
regex: normalizeRegEx( regex: '^(?!\\/_next)\\/missing-redirect-1(?:\\/)?$',
'^(?!\\/_next)\\/missing-redirect-1(?:\\/)?$'
),
source: '/missing-redirect-1', source: '/missing-redirect-1',
statusCode: 307, statusCode: 307,
}, },
...@@ -1561,9 +1554,7 @@ const runTests = (isDev = false) => { ...@@ -1561,9 +1554,7 @@ const runTests = (isDev = false) => {
type: 'query', type: 'query',
}, },
], ],
regex: normalizeRegEx( regex: '^(?!\\/_next)\\/missing-redirect-2(?:\\/)?$',
'^(?!\\/_next)\\/missing-redirect-2(?:\\/)?$'
),
source: '/missing-redirect-2', source: '/missing-redirect-2',
statusCode: 307, statusCode: 307,
}, },
...@@ -1576,17 +1567,14 @@ const runTests = (isDev = false) => { ...@@ -1576,17 +1567,14 @@ const runTests = (isDev = false) => {
value: '(?<loggedIn>true)', value: '(?<loggedIn>true)',
}, },
], ],
regex: normalizeRegEx( regex: '^(?!\\/_next)\\/missing-redirect-3(?:\\/)?$',
'^(?!\\/_next)\\/missing-redirect-3(?:\\/)?$'
),
source: '/missing-redirect-3', source: '/missing-redirect-3',
statusCode: 307, statusCode: 307,
}, },
{ {
destination: '/:lang/about', destination: '/:lang/about',
regex: normalizeRegEx( regex:
'^(?!\\/_next)\\/redirect\\/me\\/to-about(?:\\/([^\\/]+?))(?:\\/)?$' '^(?!\\/_next)\\/redirect\\/me\\/to-about(?:\\/([^\\/]+?))(?:\\/)?$',
),
source: '/redirect/me/to-about/:lang', source: '/redirect/me/to-about/:lang',
statusCode: 307, statusCode: 307,
}, },
...@@ -1594,141 +1582,127 @@ const runTests = (isDev = false) => { ...@@ -1594,141 +1582,127 @@ const runTests = (isDev = false) => {
source: '/docs/router-status/:code', source: '/docs/router-status/:code',
destination: '/docs/v2/network/status-codes#:code', destination: '/docs/v2/network/status-codes#:code',
statusCode: 301, statusCode: 301,
regex: normalizeRegEx( regex:
'^(?!\\/_next)\\/docs\\/router-status(?:\\/([^\\/]+?))(?:\\/)?$' '^(?!\\/_next)\\/docs\\/router-status(?:\\/([^\\/]+?))(?:\\/)?$',
),
}, },
{ {
source: '/docs/github', source: '/docs/github',
destination: '/docs/v2/advanced/now-for-github', destination: '/docs/v2/advanced/now-for-github',
statusCode: 301, statusCode: 301,
regex: normalizeRegEx('^(?!\\/_next)\\/docs\\/github(?:\\/)?$'), regex: '^(?!\\/_next)\\/docs\\/github(?:\\/)?$',
}, },
{ {
source: '/docs/v2/advanced/:all(.*)', source: '/docs/v2/advanced/:all(.*)',
destination: '/docs/v2/more/:all', destination: '/docs/v2/more/:all',
statusCode: 301, statusCode: 301,
regex: normalizeRegEx( regex: '^(?!\\/_next)\\/docs\\/v2\\/advanced(?:\\/(.*))(?:\\/)?$',
'^(?!\\/_next)\\/docs\\/v2\\/advanced(?:\\/(.*))(?:\\/)?$'
),
}, },
{ {
source: '/hello/:id/another', source: '/hello/:id/another',
destination: '/blog/:id', destination: '/blog/:id',
statusCode: 307, statusCode: 307,
regex: normalizeRegEx( regex: '^(?!\\/_next)\\/hello(?:\\/([^\\/]+?))\\/another(?:\\/)?$',
'^(?!\\/_next)\\/hello(?:\\/([^\\/]+?))\\/another(?:\\/)?$'
),
}, },
{ {
source: '/redirect1', source: '/redirect1',
destination: '/', destination: '/',
statusCode: 307, statusCode: 307,
regex: normalizeRegEx('^(?!\\/_next)\\/redirect1(?:\\/)?$'), regex: '^(?!\\/_next)\\/redirect1(?:\\/)?$',
}, },
{ {
source: '/redirect2', source: '/redirect2',
destination: '/', destination: '/',
statusCode: 301, statusCode: 301,
regex: normalizeRegEx('^(?!\\/_next)\\/redirect2(?:\\/)?$'), regex: '^(?!\\/_next)\\/redirect2(?:\\/)?$',
}, },
{ {
source: '/redirect3', source: '/redirect3',
destination: '/another', destination: '/another',
statusCode: 302, statusCode: 302,
regex: normalizeRegEx('^(?!\\/_next)\\/redirect3(?:\\/)?$'), regex: '^(?!\\/_next)\\/redirect3(?:\\/)?$',
}, },
{ {
source: '/redirect4', source: '/redirect4',
destination: '/', destination: '/',
statusCode: 308, statusCode: 308,
regex: normalizeRegEx('^(?!\\/_next)\\/redirect4(?:\\/)?$'), regex: '^(?!\\/_next)\\/redirect4(?:\\/)?$',
}, },
{ {
source: '/redir-chain1', source: '/redir-chain1',
destination: '/redir-chain2', destination: '/redir-chain2',
statusCode: 301, statusCode: 301,
regex: normalizeRegEx('^(?!\\/_next)\\/redir-chain1(?:\\/)?$'), regex: '^(?!\\/_next)\\/redir-chain1(?:\\/)?$',
}, },
{ {
source: '/redir-chain2', source: '/redir-chain2',
destination: '/redir-chain3', destination: '/redir-chain3',
statusCode: 302, statusCode: 302,
regex: normalizeRegEx('^(?!\\/_next)\\/redir-chain2(?:\\/)?$'), regex: '^(?!\\/_next)\\/redir-chain2(?:\\/)?$',
}, },
{ {
source: '/redir-chain3', source: '/redir-chain3',
destination: '/', destination: '/',
statusCode: 303, statusCode: 303,
regex: normalizeRegEx('^(?!\\/_next)\\/redir-chain3(?:\\/)?$'), regex: '^(?!\\/_next)\\/redir-chain3(?:\\/)?$',
}, },
{ {
destination: 'https://google.com', destination: 'https://google.com',
regex: normalizeRegEx('^(?!\\/_next)\\/to-external(?:\\/)?$'), regex: '^(?!\\/_next)\\/to-external(?:\\/)?$',
source: '/to-external', source: '/to-external',
statusCode: 307, statusCode: 307,
}, },
{ {
destination: '/with-params?first=:section&second=:name', destination: '/with-params?first=:section&second=:name',
regex: normalizeRegEx( regex:
'^(?!\\/_next)\\/query-redirect(?:\\/([^\\/]+?))(?:\\/([^\\/]+?))(?:\\/)?$' '^(?!\\/_next)\\/query-redirect(?:\\/([^\\/]+?))(?:\\/([^\\/]+?))(?:\\/)?$',
),
source: '/query-redirect/:section/:name', source: '/query-redirect/:section/:name',
statusCode: 307, statusCode: 307,
}, },
{ {
destination: '/got-unnamed', destination: '/got-unnamed',
regex: normalizeRegEx( regex:
'^(?!\\/_next)\\/unnamed(?:\\/(first|second))(?:\\/(.*))(?:\\/)?$' '^(?!\\/_next)\\/unnamed(?:\\/(first|second))(?:\\/(.*))(?:\\/)?$',
),
source: '/unnamed/(first|second)/(.*)', source: '/unnamed/(first|second)/(.*)',
statusCode: 307, statusCode: 307,
}, },
{ {
destination: '/:0', destination: '/:0',
regex: normalizeRegEx( regex:
'^(?!\\/_next)\\/named-like-unnamed(?:\\/([^\\/]+?))(?:\\/)?$' '^(?!\\/_next)\\/named-like-unnamed(?:\\/([^\\/]+?))(?:\\/)?$',
),
source: '/named-like-unnamed/:0', source: '/named-like-unnamed/:0',
statusCode: 307, statusCode: 307,
}, },
{ {
destination: '/thank-you-next', destination: '/thank-you-next',
regex: normalizeRegEx('^(?!\\/_next)\\/redirect-override(?:\\/)?$'), regex: '^(?!\\/_next)\\/redirect-override(?:\\/)?$',
source: '/redirect-override', source: '/redirect-override',
statusCode: 307, statusCode: 307,
}, },
{ {
destination: '/:first/:second', destination: '/:first/:second',
regex: normalizeRegEx( regex:
'^(?!\\/_next)\\/docs(?:\\/(integrations|now-cli))\\/v2(.*)(?:\\/)?$' '^(?!\\/_next)\\/docs(?:\\/(integrations|now-cli))\\/v2(.*)(?:\\/)?$',
),
source: '/docs/:first(integrations|now-cli)/v2:second(.*)', source: '/docs/:first(integrations|now-cli)/v2:second(.*)',
statusCode: 307, statusCode: 307,
}, },
{ {
destination: '/somewhere', destination: '/somewhere',
regex: normalizeRegEx( regex:
'^(?!\\/_next)\\/catchall-redirect(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$' '^(?!\\/_next)\\/catchall-redirect(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$',
),
source: '/catchall-redirect/:path*', source: '/catchall-redirect/:path*',
statusCode: 307, statusCode: 307,
}, },
{ {
destination: destination:
'https://authserver.example.com/set-password?returnUrl=https%3A%2F%2Fwww.example.com/login', 'https://authserver.example.com/set-password?returnUrl=https%3A%2F%2Fwww.example.com/login',
regex: normalizeRegEx( regex: '^(?!\\/_next)\\/to-external-with-query(?:\\/)?$',
'^(?!\\/_next)\\/to-external-with-query(?:\\/)?$'
),
source: '/to-external-with-query', source: '/to-external-with-query',
statusCode: 307, statusCode: 307,
}, },
{ {
destination: destination:
'https://authserver.example.com/set-password?returnUrl=https://www.example.com/login', 'https://authserver.example.com/set-password?returnUrl=https://www.example.com/login',
regex: normalizeRegEx( regex: '^(?!\\/_next)\\/to-external-with-query-2(?:\\/)?$',
'^(?!\\/_next)\\/to-external-with-query-2(?:\\/)?$'
),
source: '/to-external-with-query-2', source: '/to-external-with-query-2',
statusCode: 307, statusCode: 307,
}, },
...@@ -1741,7 +1715,7 @@ const runTests = (isDev = false) => { ...@@ -1741,7 +1715,7 @@ const runTests = (isDev = false) => {
value: '(?<myHeader>.*)', value: '(?<myHeader>.*)',
}, },
], ],
regex: normalizeRegEx('^(?!\\/_next)\\/has-redirect-1(?:\\/)?$'), regex: '^(?!\\/_next)\\/has-redirect-1(?:\\/)?$',
source: '/has-redirect-1', source: '/has-redirect-1',
statusCode: 307, statusCode: 307,
}, },
...@@ -1753,7 +1727,7 @@ const runTests = (isDev = false) => { ...@@ -1753,7 +1727,7 @@ const runTests = (isDev = false) => {
type: 'query', type: 'query',
}, },
], ],
regex: normalizeRegEx('^(?!\\/_next)\\/has-redirect-2(?:\\/)?$'), regex: '^(?!\\/_next)\\/has-redirect-2(?:\\/)?$',
source: '/has-redirect-2', source: '/has-redirect-2',
statusCode: 307, statusCode: 307,
}, },
...@@ -1766,7 +1740,7 @@ const runTests = (isDev = false) => { ...@@ -1766,7 +1740,7 @@ const runTests = (isDev = false) => {
value: 'true', value: 'true',
}, },
], ],
regex: normalizeRegEx('^(?!\\/_next)\\/has-redirect-3(?:\\/)?$'), regex: '^(?!\\/_next)\\/has-redirect-3(?:\\/)?$',
source: '/has-redirect-3', source: '/has-redirect-3',
statusCode: 307, statusCode: 307,
}, },
...@@ -1778,7 +1752,7 @@ const runTests = (isDev = false) => { ...@@ -1778,7 +1752,7 @@ const runTests = (isDev = false) => {
value: 'example.com', value: 'example.com',
}, },
], ],
regex: normalizeRegEx('^(?!\\/_next)\\/has-redirect-4(?:\\/)?$'), regex: '^(?!\\/_next)\\/has-redirect-4(?:\\/)?$',
source: '/has-redirect-4', source: '/has-redirect-4',
statusCode: 307, statusCode: 307,
}, },
...@@ -1790,9 +1764,7 @@ const runTests = (isDev = false) => { ...@@ -1790,9 +1764,7 @@ const runTests = (isDev = false) => {
type: 'header', type: 'header',
}, },
], ],
regex: normalizeRegEx( regex: '^(?!\\/_next)(?:\\/([^\\/]+?))\\/has-redirect-5(?:\\/)?$',
'^(?!\\/_next)(?:\\/([^\\/]+?))\\/has-redirect-5(?:\\/)?$'
),
source: '/:path/has-redirect-5', source: '/:path/has-redirect-5',
statusCode: 307, statusCode: 307,
}, },
...@@ -1804,13 +1776,13 @@ const runTests = (isDev = false) => { ...@@ -1804,13 +1776,13 @@ const runTests = (isDev = false) => {
value: '(?<subdomain>.*)-test.example.com', value: '(?<subdomain>.*)-test.example.com',
}, },
], ],
regex: normalizeRegEx('^(?!\\/_next)\\/has-redirect-6(?:\\/)?$'), regex: '^(?!\\/_next)\\/has-redirect-6(?:\\/)?$',
source: '/has-redirect-6', source: '/has-redirect-6',
statusCode: 307, statusCode: 307,
}, },
{ {
source: '/has-redirect-7', source: '/has-redirect-7',
regex: normalizeRegEx('^(?!\\/_next)\\/has-redirect-7(?:\\/)?$'), regex: '^(?!\\/_next)\\/has-redirect-7(?:\\/)?$',
has: [ has: [
{ {
type: 'query', type: 'query',
...@@ -1821,7 +1793,7 @@ const runTests = (isDev = false) => { ...@@ -1821,7 +1793,7 @@ const runTests = (isDev = false) => {
destination: '/somewhere?value=:hello', destination: '/somewhere?value=:hello',
statusCode: 307, statusCode: 307,
}, },
], ].map((item) => normalizeRouteRegExes(item)),
headers: [ headers: [
{ {
headers: [ headers: [
...@@ -1837,7 +1809,7 @@ const runTests = (isDev = false) => { ...@@ -1837,7 +1809,7 @@ const runTests = (isDev = false) => {
value: '(?<myHeader>.*)', value: '(?<myHeader>.*)',
}, },
], ],
regex: normalizeRegEx('^\\/missing-headers-1(?:\\/)?$'), regex: '^\\/missing-headers-1(?:\\/)?$',
source: '/missing-headers-1', source: '/missing-headers-1',
}, },
{ {
...@@ -1853,7 +1825,7 @@ const runTests = (isDev = false) => { ...@@ -1853,7 +1825,7 @@ const runTests = (isDev = false) => {
type: 'query', type: 'query',
}, },
], ],
regex: normalizeRegEx('^\\/missing-headers-2(?:\\/)?$'), regex: '^\\/missing-headers-2(?:\\/)?$',
source: '/missing-headers-2', source: '/missing-headers-2',
}, },
{ {
...@@ -1870,7 +1842,7 @@ const runTests = (isDev = false) => { ...@@ -1870,7 +1842,7 @@ const runTests = (isDev = false) => {
value: '(?<loggedIn>true)', value: '(?<loggedIn>true)',
}, },
], ],
regex: normalizeRegEx('^\\/missing-headers-3(?:\\/)?$'), regex: '^\\/missing-headers-3(?:\\/)?$',
source: '/missing-headers-3', source: '/missing-headers-3',
}, },
{ {
...@@ -1884,7 +1856,7 @@ const runTests = (isDev = false) => { ...@@ -1884,7 +1856,7 @@ const runTests = (isDev = false) => {
value: 'hello again', value: 'hello again',
}, },
], ],
regex: normalizeRegEx('^\\/add-header(?:\\/)?$'), regex: '^\\/add-header(?:\\/)?$',
source: '/add-header', source: '/add-header',
}, },
{ {
...@@ -1898,7 +1870,7 @@ const runTests = (isDev = false) => { ...@@ -1898,7 +1870,7 @@ const runTests = (isDev = false) => {
value: 'second', value: 'second',
}, },
], ],
regex: normalizeRegEx('^\\/my-headers(?:\\/(.*))(?:\\/)?$'), regex: '^\\/my-headers(?:\\/(.*))(?:\\/)?$',
source: '/my-headers/(.*)', source: '/my-headers/(.*)',
}, },
{ {
...@@ -1953,9 +1925,7 @@ const runTests = (isDev = false) => { ...@@ -1953,9 +1925,7 @@ const runTests = (isDev = false) => {
"default-src 'self'; img-src *; media-src media1.com media2.com; script-src userscripts.example.com/:path", "default-src 'self'; img-src *; media-src media1.com media2.com; script-src userscripts.example.com/:path",
}, },
], ],
regex: normalizeRegEx( regex: '^\\/my-other-header(?:\\/([^\\/]+?))(?:\\/)?$',
'^\\/my-other-header(?:\\/([^\\/]+?))(?:\\/)?$'
),
source: '/my-other-header/:path', source: '/my-other-header/:path',
}, },
{ {
...@@ -1965,7 +1935,7 @@ const runTests = (isDev = false) => { ...@@ -1965,7 +1935,7 @@ const runTests = (isDev = false) => {
value: 'https://example.com', value: 'https://example.com',
}, },
], ],
regex: normalizeRegEx('^\\/without-params\\/url(?:\\/)?$'), regex: '^\\/without-params\\/url(?:\\/)?$',
source: '/without-params/url', source: '/without-params/url',
}, },
{ {
...@@ -1975,9 +1945,8 @@ const runTests = (isDev = false) => { ...@@ -1975,9 +1945,8 @@ const runTests = (isDev = false) => {
value: 'https://example.com/:path*', value: 'https://example.com/:path*',
}, },
], ],
regex: normalizeRegEx( regex:
'^\\/with-params\\/url(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$' '^\\/with-params\\/url(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$',
),
source: '/with-params/url/:path*', source: '/with-params/url/:path*',
}, },
{ {
...@@ -1987,9 +1956,8 @@ const runTests = (isDev = false) => { ...@@ -1987,9 +1956,8 @@ const runTests = (isDev = false) => {
value: 'https://example.com:8080?hello=:path*', value: 'https://example.com:8080?hello=:path*',
}, },
], ],
regex: normalizeRegEx( regex:
'^\\/with-params\\/url2(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$' '^\\/with-params\\/url2(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$',
),
source: '/with-params/url2/:path*', source: '/with-params/url2/:path*',
}, },
{ {
...@@ -1999,9 +1967,7 @@ const runTests = (isDev = false) => { ...@@ -1999,9 +1967,7 @@ const runTests = (isDev = false) => {
value: 'applied-everywhere', value: 'applied-everywhere',
}, },
], ],
regex: normalizeRegEx( regex: '^(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$',
'^(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$'
),
source: '/:path*', source: '/:path*',
}, },
{ {
...@@ -2015,7 +1981,7 @@ const runTests = (isDev = false) => { ...@@ -2015,7 +1981,7 @@ const runTests = (isDev = false) => {
value: 'end', value: 'end',
}, },
], ],
regex: normalizeRegEx('^\\/named-pattern(?:\\/(.*))(?:\\/)?$'), regex: '^\\/named-pattern(?:\\/(.*))(?:\\/)?$',
source: '/named-pattern/:path(.*)', source: '/named-pattern/:path(.*)',
}, },
{ {
...@@ -2025,9 +1991,8 @@ const runTests = (isDev = false) => { ...@@ -2025,9 +1991,8 @@ const runTests = (isDev = false) => {
value: ':path*', value: ':path*',
}, },
], ],
regex: normalizeRegEx( regex:
'^\\/catchall-header(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$' '^\\/catchall-header(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$',
),
source: '/catchall-header/:path*', source: '/catchall-header/:path*',
}, },
{ {
...@@ -2044,7 +2009,7 @@ const runTests = (isDev = false) => { ...@@ -2044,7 +2009,7 @@ const runTests = (isDev = false) => {
value: 'header', value: 'header',
}, },
], ],
regex: normalizeRegEx('^\\/has-header-1(?:\\/)?$'), regex: '^\\/has-header-1(?:\\/)?$',
source: '/has-header-1', source: '/has-header-1',
}, },
{ {
...@@ -2060,7 +2025,7 @@ const runTests = (isDev = false) => { ...@@ -2060,7 +2025,7 @@ const runTests = (isDev = false) => {
value: 'value', value: 'value',
}, },
], ],
regex: normalizeRegEx('^\\/has-header-2(?:\\/)?$'), regex: '^\\/has-header-2(?:\\/)?$',
source: '/has-header-2', source: '/has-header-2',
}, },
{ {
...@@ -2077,7 +2042,7 @@ const runTests = (isDev = false) => { ...@@ -2077,7 +2042,7 @@ const runTests = (isDev = false) => {
value: 'yuuuup', value: 'yuuuup',
}, },
], ],
regex: normalizeRegEx('^\\/has-header-3(?:\\/)?$'), regex: '^\\/has-header-3(?:\\/)?$',
source: '/has-header-3', source: '/has-header-3',
}, },
{ {
...@@ -2093,10 +2058,10 @@ const runTests = (isDev = false) => { ...@@ -2093,10 +2058,10 @@ const runTests = (isDev = false) => {
value: 'yuuuup', value: 'yuuuup',
}, },
], ],
regex: normalizeRegEx('^\\/has-header-4(?:\\/)?$'), regex: '^\\/has-header-4(?:\\/)?$',
source: '/has-header-4', source: '/has-header-4',
}, },
], ].map((item) => normalizeRouteRegExes(item)),
rewrites: { rewrites: {
beforeFiles: [ beforeFiles: [
{ {
...@@ -2107,188 +2072,174 @@ const runTests = (isDev = false) => { ...@@ -2107,188 +2072,174 @@ const runTests = (isDev = false) => {
type: 'query', type: 'query',
}, },
], ],
regex: normalizeRegEx('^\\/hello(?:\\/)?$'), regex: '^\\/hello(?:\\/)?$',
source: '/hello', source: '/hello',
}, },
{ {
destination: '/blog/:path*', destination: '/blog/:path*',
regex: normalizeRegEx( regex:
'^\\/old-blog(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$' '^\\/old-blog(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$',
),
source: '/old-blog/:path*', source: '/old-blog/:path*',
}, },
{ {
destination: 'https://example.vercel.sh', destination: 'https://example.vercel.sh',
regex: normalizeRegEx('^\\/overridden(?:\\/)?$'), regex: '^\\/overridden(?:\\/)?$',
source: '/overridden', source: '/overridden',
}, },
{ {
destination: '/_sport/nfl/:path*', destination: '/_sport/nfl/:path*',
regex: normalizeRegEx( regex:
'^\\/nfl(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$' '^\\/nfl(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$',
),
source: '/nfl/:path*', source: '/nfl/:path*',
}, },
], ].map((item) => normalizeRouteRegExes(item)),
afterFiles: [ afterFiles: [
{ {
destination: `http://localhost:${externalServerPort}/_next/webpack-hmr?page=/about`, destination: `http://localhost:${externalServerPort}/_next/webpack-hmr?page=/about`,
regex: normalizeRegEx('^\\/to-websocket(?:\\/)?$'), regex: '^\\/to-websocket(?:\\/)?$',
source: '/to-websocket', source: '/to-websocket',
}, },
{ {
destination: '/hello', destination: '/hello',
regex: normalizeRegEx('^\\/websocket-to-page(?:\\/)?$'), regex: '^\\/websocket-to-page(?:\\/)?$',
source: '/websocket-to-page', source: '/websocket-to-page',
}, },
{ {
destination: 'http://localhost:12233', destination: 'http://localhost:12233',
regex: normalizeRegEx('^\\/to-nowhere(?:\\/)?$'), regex: '^\\/to-nowhere(?:\\/)?$',
source: '/to-nowhere', source: '/to-nowhere',
}, },
{ {
destination: '/auto-export/hello?rewrite=1', destination: '/auto-export/hello?rewrite=1',
regex: normalizeRegEx('^\\/rewriting-to-auto-export(?:\\/)?$'), regex: '^\\/rewriting-to-auto-export(?:\\/)?$',
source: '/rewriting-to-auto-export', source: '/rewriting-to-auto-export',
}, },
{ {
destination: '/auto-export/another?rewrite=1', destination: '/auto-export/another?rewrite=1',
regex: normalizeRegEx( regex:
'^\\/rewriting-to-another-auto-export(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$' '^\\/rewriting-to-another-auto-export(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$',
),
source: '/rewriting-to-another-auto-export/:path*', source: '/rewriting-to-another-auto-export/:path*',
}, },
{ {
destination: '/another/one', destination: '/another/one',
regex: normalizeRegEx('^\\/to-another(?:\\/)?$'), regex: '^\\/to-another(?:\\/)?$',
source: '/to-another', source: '/to-another',
}, },
{ {
destination: '/404', destination: '/404',
regex: normalizeRegEx('^\\/nav(?:\\/)?$'), regex: '^\\/nav(?:\\/)?$',
source: '/nav', source: '/nav',
}, },
{ {
source: '/hello-world', source: '/hello-world',
destination: '/static/hello.txt', destination: '/static/hello.txt',
regex: normalizeRegEx('^\\/hello-world(?:\\/)?$'), regex: '^\\/hello-world(?:\\/)?$',
}, },
{ {
source: '/', source: '/',
destination: '/another', destination: '/another',
regex: normalizeRegEx('^\\/(?:\\/)?$'), regex: '^\\/(?:\\/)?$',
}, },
{ {
source: '/another', source: '/another',
destination: '/multi-rewrites', destination: '/multi-rewrites',
regex: normalizeRegEx('^\\/another(?:\\/)?$'), regex: '^\\/another(?:\\/)?$',
}, },
{ {
source: '/first', source: '/first',
destination: '/hello', destination: '/hello',
regex: normalizeRegEx('^\\/first(?:\\/)?$'), regex: '^\\/first(?:\\/)?$',
}, },
{ {
source: '/second', source: '/second',
destination: '/hello-again', destination: '/hello-again',
regex: normalizeRegEx('^\\/second(?:\\/)?$'), regex: '^\\/second(?:\\/)?$',
}, },
{ {
destination: '/hello', destination: '/hello',
regex: normalizeRegEx('^\\/to-hello(?:\\/)?$'), regex: '^\\/to-hello(?:\\/)?$',
source: '/to-hello', source: '/to-hello',
}, },
{ {
destination: '/blog/post-2', destination: '/blog/post-2',
regex: normalizeRegEx('^\\/blog\\/post-1(?:\\/)?$'), regex: '^\\/blog\\/post-1(?:\\/)?$',
source: '/blog/post-1', source: '/blog/post-1',
}, },
{ {
source: '/test/:path', source: '/test/:path',
destination: '/:path', destination: '/:path',
regex: normalizeRegEx('^\\/test(?:\\/([^\\/]+?))(?:\\/)?$'), regex: '^\\/test(?:\\/([^\\/]+?))(?:\\/)?$',
}, },
{ {
source: '/test-overwrite/:something/:another', source: '/test-overwrite/:something/:another',
destination: '/params/this-should-be-the-value', destination: '/params/this-should-be-the-value',
regex: normalizeRegEx( regex:
'^\\/test-overwrite(?:\\/([^\\/]+?))(?:\\/([^\\/]+?))(?:\\/)?$' '^\\/test-overwrite(?:\\/([^\\/]+?))(?:\\/([^\\/]+?))(?:\\/)?$',
),
}, },
{ {
source: '/params/:something', source: '/params/:something',
destination: '/with-params', destination: '/with-params',
regex: normalizeRegEx('^\\/params(?:\\/([^\\/]+?))(?:\\/)?$'), regex: '^\\/params(?:\\/([^\\/]+?))(?:\\/)?$',
}, },
{ {
destination: '/with-params?first=:section&second=:name', destination: '/with-params?first=:section&second=:name',
regex: normalizeRegEx( regex:
'^\\/query-rewrite(?:\\/([^\\/]+?))(?:\\/([^\\/]+?))(?:\\/)?$' '^\\/query-rewrite(?:\\/([^\\/]+?))(?:\\/([^\\/]+?))(?:\\/)?$',
),
source: '/query-rewrite/:section/:name', source: '/query-rewrite/:section/:name',
}, },
{ {
destination: '/_next/:path*', destination: '/_next/:path*',
regex: normalizeRegEx( regex:
'^\\/hidden\\/_next(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$' '^\\/hidden\\/_next(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$',
),
source: '/hidden/_next/:path*', source: '/hidden/_next/:path*',
}, },
{ {
destination: `http://localhost:${externalServerPort}/:path*`, destination: `http://localhost:${externalServerPort}/:path*`,
regex: normalizeRegEx( regex:
'^\\/proxy-me(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$' '^\\/proxy-me(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$',
),
source: '/proxy-me/:path*', source: '/proxy-me/:path*',
}, },
{ {
destination: '/api/hello', destination: '/api/hello',
regex: normalizeRegEx('^\\/api-hello(?:\\/)?$'), regex: '^\\/api-hello(?:\\/)?$',
source: '/api-hello', source: '/api-hello',
}, },
{ {
destination: '/api/hello?name=:first*', destination: '/api/hello?name=:first*',
regex: normalizeRegEx('^\\/api-hello-regex(?:\\/(.*))(?:\\/)?$'), regex: '^\\/api-hello-regex(?:\\/(.*))(?:\\/)?$',
source: '/api-hello-regex/:first(.*)', source: '/api-hello-regex/:first(.*)',
}, },
{ {
destination: '/api/hello?hello=:name', destination: '/api/hello?hello=:name',
regex: normalizeRegEx( regex: '^\\/api-hello-param(?:\\/([^\\/]+?))(?:\\/)?$',
'^\\/api-hello-param(?:\\/([^\\/]+?))(?:\\/)?$'
),
source: '/api-hello-param/:name', source: '/api-hello-param/:name',
}, },
{ {
destination: '/api/dynamic/:name?hello=:name', destination: '/api/dynamic/:name?hello=:name',
regex: normalizeRegEx( regex: '^\\/api-dynamic-param(?:\\/([^\\/]+?))(?:\\/)?$',
'^\\/api-dynamic-param(?:\\/([^\\/]+?))(?:\\/)?$'
),
source: '/api-dynamic-param/:name', source: '/api-dynamic-param/:name',
}, },
{ {
destination: '/with-params', destination: '/with-params',
regex: normalizeRegEx('^(?:\\/([^\\/]+?))\\/post-321(?:\\/)?$'), regex: '^(?:\\/([^\\/]+?))\\/post-321(?:\\/)?$',
source: '/:path/post-321', source: '/:path/post-321',
}, },
{ {
destination: '/with-params', destination: '/with-params',
regex: normalizeRegEx( regex:
'^\\/unnamed-params\\/nested(?:\\/(.*))(?:\\/([^\\/]+?))(?:\\/(.*))(?:\\/)?$' '^\\/unnamed-params\\/nested(?:\\/(.*))(?:\\/([^\\/]+?))(?:\\/(.*))(?:\\/)?$',
),
source: '/unnamed-params/nested/(.*)/:test/(.*)', source: '/unnamed-params/nested/(.*)/:test/(.*)',
}, },
{ {
destination: '/with-params', destination: '/with-params',
regex: normalizeRegEx( regex:
'^\\/catchall-rewrite(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$' '^\\/catchall-rewrite(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$',
),
source: '/catchall-rewrite/:path*', source: '/catchall-rewrite/:path*',
}, },
{ {
destination: '/with-params?another=:path*', destination: '/with-params?another=:path*',
regex: normalizeRegEx( regex:
'^\\/catchall-query(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$' '^\\/catchall-query(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$',
),
source: '/catchall-query/:path*', source: '/catchall-query/:path*',
}, },
{ {
...@@ -2300,7 +2251,7 @@ const runTests = (isDev = false) => { ...@@ -2300,7 +2251,7 @@ const runTests = (isDev = false) => {
value: '(?<myHeader>.*)', value: '(?<myHeader>.*)',
}, },
], ],
regex: normalizeRegEx('^\\/has-rewrite-1(?:\\/)?$'), regex: '^\\/has-rewrite-1(?:\\/)?$',
source: '/has-rewrite-1', source: '/has-rewrite-1',
}, },
{ {
...@@ -2311,7 +2262,7 @@ const runTests = (isDev = false) => { ...@@ -2311,7 +2262,7 @@ const runTests = (isDev = false) => {
type: 'query', type: 'query',
}, },
], ],
regex: normalizeRegEx('^\\/has-rewrite-2(?:\\/)?$'), regex: '^\\/has-rewrite-2(?:\\/)?$',
source: '/has-rewrite-2', source: '/has-rewrite-2',
}, },
{ {
...@@ -2323,7 +2274,7 @@ const runTests = (isDev = false) => { ...@@ -2323,7 +2274,7 @@ const runTests = (isDev = false) => {
value: '(?<loggedIn>true)', value: '(?<loggedIn>true)',
}, },
], ],
regex: normalizeRegEx('^\\/has-rewrite-3(?:\\/)?$'), regex: '^\\/has-rewrite-3(?:\\/)?$',
source: '/has-rewrite-3', source: '/has-rewrite-3',
}, },
{ {
...@@ -2334,7 +2285,7 @@ const runTests = (isDev = false) => { ...@@ -2334,7 +2285,7 @@ const runTests = (isDev = false) => {
value: 'example.com', value: 'example.com',
}, },
], ],
regex: normalizeRegEx('^\\/has-rewrite-4(?:\\/)?$'), regex: '^\\/has-rewrite-4(?:\\/)?$',
source: '/has-rewrite-4', source: '/has-rewrite-4',
}, },
{ {
...@@ -2345,7 +2296,7 @@ const runTests = (isDev = false) => { ...@@ -2345,7 +2296,7 @@ const runTests = (isDev = false) => {
type: 'query', type: 'query',
}, },
], ],
regex: normalizeRegEx('^\\/has-rewrite-5(?:\\/)?$'), regex: '^\\/has-rewrite-5(?:\\/)?$',
source: '/has-rewrite-5', source: '/has-rewrite-5',
}, },
{ {
...@@ -2357,7 +2308,7 @@ const runTests = (isDev = false) => { ...@@ -2357,7 +2308,7 @@ const runTests = (isDev = false) => {
value: 'with-params', value: 'with-params',
}, },
], ],
regex: normalizeRegEx('^\\/has-rewrite-6(?:\\/)?$'), regex: '^\\/has-rewrite-6(?:\\/)?$',
source: '/has-rewrite-6', source: '/has-rewrite-6',
}, },
{ {
...@@ -2369,7 +2320,7 @@ const runTests = (isDev = false) => { ...@@ -2369,7 +2320,7 @@ const runTests = (isDev = false) => {
value: '(?<idk>with-params|hello)', value: '(?<idk>with-params|hello)',
}, },
], ],
regex: normalizeRegEx('^\\/has-rewrite-7(?:\\/)?$'), regex: '^\\/has-rewrite-7(?:\\/)?$',
source: '/has-rewrite-7', source: '/has-rewrite-7',
}, },
{ {
...@@ -2380,7 +2331,7 @@ const runTests = (isDev = false) => { ...@@ -2380,7 +2331,7 @@ const runTests = (isDev = false) => {
type: 'query', type: 'query',
}, },
], ],
regex: normalizeRegEx('^\\/has-rewrite-8(?:\\/)?$'), regex: '^\\/has-rewrite-8(?:\\/)?$',
source: '/has-rewrite-8', source: '/has-rewrite-8',
}, },
{ {
...@@ -2392,7 +2343,7 @@ const runTests = (isDev = false) => { ...@@ -2392,7 +2343,7 @@ const runTests = (isDev = false) => {
value: '(?<myHeader>.*)', value: '(?<myHeader>.*)',
}, },
], ],
regex: normalizeRegEx('^\\/missing-rewrite-1(?:\\/)?$'), regex: '^\\/missing-rewrite-1(?:\\/)?$',
source: '/missing-rewrite-1', source: '/missing-rewrite-1',
}, },
{ {
...@@ -2403,7 +2354,7 @@ const runTests = (isDev = false) => { ...@@ -2403,7 +2354,7 @@ const runTests = (isDev = false) => {
type: 'query', type: 'query',
}, },
], ],
regex: normalizeRegEx('^\\/missing-rewrite-2(?:\\/)?$'), regex: '^\\/missing-rewrite-2(?:\\/)?$',
source: '/missing-rewrite-2', source: '/missing-rewrite-2',
}, },
{ {
...@@ -2415,12 +2366,12 @@ const runTests = (isDev = false) => { ...@@ -2415,12 +2366,12 @@ const runTests = (isDev = false) => {
value: '(?<loggedIn>true)', value: '(?<loggedIn>true)',
}, },
], ],
regex: normalizeRegEx('^\\/missing-rewrite-3(?:\\/)?$'), regex: '^\\/missing-rewrite-3(?:\\/)?$',
source: '/missing-rewrite-3', source: '/missing-rewrite-3',
}, },
{ {
destination: '/hello', destination: '/hello',
regex: normalizeRegEx('^\\/blog\\/about(?:\\/)?$'), regex: '^\\/blog\\/about(?:\\/)?$',
source: '/blog/about', source: '/blog/about',
}, },
{ {
...@@ -2429,14 +2380,14 @@ const runTests = (isDev = false) => { ...@@ -2429,14 +2380,14 @@ const runTests = (isDev = false) => {
'^\\/overridden(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$', '^\\/overridden(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$',
source: '/overridden/:path*', source: '/overridden/:path*',
}, },
], ].map((item) => normalizeRouteRegExes(item)),
fallback: [], fallback: [],
}, },
dynamicRoutes: [ dynamicRoutes: [
{ {
namedRegex: '^/_sport/(?<nxtPslug>[^/]+?)(?:/)?$', namedRegex: '^/_sport/(?<nxtPslug>[^/]+?)(?:/)?$',
page: '/_sport/[slug]', page: '/_sport/[slug]',
regex: normalizeRegEx('^\\/_sport\\/([^\\/]+?)(?:\\/)?$'), regex: '^\\/_sport\\/([^\\/]+?)(?:\\/)?$',
routeKeys: { routeKeys: {
nxtPslug: 'nxtPslug', nxtPslug: 'nxtPslug',
}, },
...@@ -2444,7 +2395,7 @@ const runTests = (isDev = false) => { ...@@ -2444,7 +2395,7 @@ const runTests = (isDev = false) => {
{ {
namedRegex: '^/_sport/(?<nxtPslug>[^/]+?)/test(?:/)?$', namedRegex: '^/_sport/(?<nxtPslug>[^/]+?)/test(?:/)?$',
page: '/_sport/[slug]/test', page: '/_sport/[slug]/test',
regex: normalizeRegEx('^\\/_sport\\/([^\\/]+?)\\/test(?:\\/)?$'), regex: '^\\/_sport\\/([^\\/]+?)\\/test(?:\\/)?$',
routeKeys: { routeKeys: {
nxtPslug: 'nxtPslug', nxtPslug: 'nxtPslug',
}, },
...@@ -2452,7 +2403,7 @@ const runTests = (isDev = false) => { ...@@ -2452,7 +2403,7 @@ const runTests = (isDev = false) => {
{ {
namedRegex: '^/another/(?<nxtPid>[^/]+?)(?:/)?$', namedRegex: '^/another/(?<nxtPid>[^/]+?)(?:/)?$',
page: '/another/[id]', page: '/another/[id]',
regex: normalizeRegEx('^\\/another\\/([^\\/]+?)(?:\\/)?$'), regex: '^\\/another\\/([^\\/]+?)(?:\\/)?$',
routeKeys: { routeKeys: {
nxtPid: 'nxtPid', nxtPid: 'nxtPid',
}, },
...@@ -2460,7 +2411,7 @@ const runTests = (isDev = false) => { ...@@ -2460,7 +2411,7 @@ const runTests = (isDev = false) => {
{ {
namedRegex: '^/api/dynamic/(?<nxtPslug>[^/]+?)(?:/)?$', namedRegex: '^/api/dynamic/(?<nxtPslug>[^/]+?)(?:/)?$',
page: '/api/dynamic/[slug]', page: '/api/dynamic/[slug]',
regex: normalizeRegEx('^\\/api\\/dynamic\\/([^\\/]+?)(?:\\/)?$'), regex: '^\\/api\\/dynamic\\/([^\\/]+?)(?:\\/)?$',
routeKeys: { routeKeys: {
nxtPslug: 'nxtPslug', nxtPslug: 'nxtPslug',
}, },
...@@ -2468,7 +2419,7 @@ const runTests = (isDev = false) => { ...@@ -2468,7 +2419,7 @@ const runTests = (isDev = false) => {
{ {
namedRegex: '^/auto\\-export/(?<nxtPslug>[^/]+?)(?:/)?$', namedRegex: '^/auto\\-export/(?<nxtPslug>[^/]+?)(?:/)?$',
page: '/auto-export/[slug]', page: '/auto-export/[slug]',
regex: normalizeRegEx('^\\/auto\\-export\\/([^\\/]+?)(?:\\/)?$'), regex: '^\\/auto\\-export\\/([^\\/]+?)(?:\\/)?$',
routeKeys: { routeKeys: {
nxtPslug: 'nxtPslug', nxtPslug: 'nxtPslug',
}, },
...@@ -2476,7 +2427,7 @@ const runTests = (isDev = false) => { ...@@ -2476,7 +2427,7 @@ const runTests = (isDev = false) => {
{ {
namedRegex: '^/blog/(?<nxtPpost>[^/]+?)(?:/)?$', namedRegex: '^/blog/(?<nxtPpost>[^/]+?)(?:/)?$',
page: '/blog/[post]', page: '/blog/[post]',
regex: normalizeRegEx('^\\/blog\\/([^\\/]+?)(?:\\/)?$'), regex: '^\\/blog\\/([^\\/]+?)(?:\\/)?$',
routeKeys: { routeKeys: {
nxtPpost: 'nxtPpost', nxtPpost: 'nxtPpost',
}, },
...@@ -2484,7 +2435,7 @@ const runTests = (isDev = false) => { ...@@ -2484,7 +2435,7 @@ const runTests = (isDev = false) => {
{ {
namedRegex: '^/blog\\-catchall/(?<nxtPslug>.+?)(?:/)?$', namedRegex: '^/blog\\-catchall/(?<nxtPslug>.+?)(?:/)?$',
page: '/blog-catchall/[...slug]', page: '/blog-catchall/[...slug]',
regex: normalizeRegEx('^\\/blog\\-catchall\\/(.+?)(?:\\/)?$'), regex: '^\\/blog\\-catchall\\/(.+?)(?:\\/)?$',
routeKeys: { routeKeys: {
nxtPslug: 'nxtPslug', nxtPslug: 'nxtPslug',
}, },
...@@ -2497,7 +2448,7 @@ const runTests = (isDev = false) => { ...@@ -2497,7 +2448,7 @@ const runTests = (isDev = false) => {
nxtPslug: 'nxtPslug', nxtPslug: 'nxtPslug',
}, },
}, },
], ].map((item) => normalizeRouteRegExes(item)),
staticRoutes: [ staticRoutes: [
{ {
namedRegex: '^/auto\\-export/another(?:/)?$', namedRegex: '^/auto\\-export/another(?:/)?$',
...@@ -2553,7 +2504,7 @@ const runTests = (isDev = false) => { ...@@ -2553,7 +2504,7 @@ const runTests = (isDev = false) => {
regex: '^/with\\-params(?:/)?$', regex: '^/with\\-params(?:/)?$',
routeKeys: {}, routeKeys: {},
}, },
], ].map((item) => normalizeRouteRegExes(item)),
rsc: { rsc: {
header: 'RSC', header: 'RSC',
contentTypeHeader: 'text/x-component', contentTypeHeader: 'text/x-component',
......
// this checks priority issues with catch-all routes that // this checks priority issues with catch-all routes that
// can match `_next/data/build-id/path.json // can match `_next/data/build-id/path.json
export function getServerSideProps() { export function getServerSideProps({ req }) {
if (req.url.startsWith('/_next/static')) {
return {
props: {
now: Date.now(),
},
}
}
return { return {
notFound: true, notFound: true,
} }
......
...@@ -13,10 +13,10 @@ import { ...@@ -13,10 +13,10 @@ import {
waitFor, waitFor,
nextBuild, nextBuild,
nextStart, nextStart,
normalizeRegEx,
check, check,
hasRedbox, hasRedbox,
getRedboxHeader, getRedboxHeader,
normalizeRouteRegExes,
} from 'next-test-utils' } from 'next-test-utils'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import escapeRegex from 'escape-string-regexp' import escapeRegex from 'escape-string-regexp'
...@@ -28,6 +28,13 @@ const appDir = join(__dirname, '../') ...@@ -28,6 +28,13 @@ const appDir = join(__dirname, '../')
const buildIdPath = join(appDir, '.next/BUILD_ID') const buildIdPath = join(appDir, '.next/BUILD_ID')
function runTests({ dev }) { function runTests({ dev }) {
it('should not match dynamic route for non-existent _next/static asset', async () => {
const res = await fetchViaHTTP(appPort, '/_next/static/non-existent')
expect(res.status).toBe(404)
expect(await res.text()).not.toContain('nested catch-all')
})
if (!dev) { if (!dev) {
it('should have correct cache entries on prefetch', async () => { it('should have correct cache entries on prefetch', async () => {
const browser = await webdriver(appPort, '/') const browser = await webdriver(appPort, '/')
...@@ -1234,21 +1241,15 @@ function runTests({ dev }) { ...@@ -1234,21 +1241,15 @@ function runTests({ dev }) {
join(appDir, '.next/routes-manifest.json') join(appDir, '.next/routes-manifest.json')
) )
for (const route of manifest.dynamicRoutes) { manifest.staticRoutes = manifest.staticRoutes.map((item) =>
route.regex = normalizeRegEx(route.regex) normalizeRouteRegExes(item)
)
// ensure regexes are valid manifest.dynamicRoutes = manifest.dynamicRoutes.map((item) =>
new RegExp(route.regex) normalizeRouteRegExes(item)
new RegExp(route.namedRegex) )
} manifest.dataRoutes = manifest.dataRoutes.map((item) =>
normalizeRouteRegExes(item)
for (const route of manifest.dataRoutes) { )
route.dataRouteRegex = normalizeRegEx(route.dataRouteRegex)
// ensure regexes are valid
new RegExp(route.dataRouteRegex)
new RegExp(route.namedDataRouteRegex)
}
expect(manifest).toEqual({ expect(manifest).toEqual({
version: 3, version: 3,
...@@ -1270,7 +1271,7 @@ function runTests({ dev }) { ...@@ -1270,7 +1271,7 @@ function runTests({ dev }) {
regex: '^/another(?:/)?$', regex: '^/another(?:/)?$',
routeKeys: {}, routeKeys: {},
}, },
], ].map((item) => normalizeRouteRegExes(item)),
redirects: expect.arrayContaining([]), redirects: expect.arrayContaining([]),
dataRoutes: [ dataRoutes: [
{ {
...@@ -1301,11 +1302,9 @@ function runTests({ dev }) { ...@@ -1301,11 +1302,9 @@ function runTests({ dev }) {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId buildId
)}/p1/p2/all\\-ssg/(?<nxtPrest>.+?)\\.json$`, )}/p1/p2/all\\-ssg/(?<nxtPrest>.+?)\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
`^\\/_next\\/data\\/${escapeRegex( buildId
buildId )}\\/p1\\/p2\\/all\\-ssg\\/(.+?)\\.json$`,
)}\\/p1\\/p2\\/all\\-ssg\\/(.+?)\\.json$`
),
page: '/p1/p2/all-ssg/[...rest]', page: '/p1/p2/all-ssg/[...rest]',
routeKeys: { routeKeys: {
nxtPrest: 'nxtPrest', nxtPrest: 'nxtPrest',
...@@ -1315,11 +1314,9 @@ function runTests({ dev }) { ...@@ -1315,11 +1314,9 @@ function runTests({ dev }) {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId buildId
)}/p1/p2/nested\\-all\\-ssg/(?<nxtPrest>.+?)\\.json$`, )}/p1/p2/nested\\-all\\-ssg/(?<nxtPrest>.+?)\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
`^\\/_next\\/data\\/${escapeRegex( buildId
buildId )}\\/p1\\/p2\\/nested\\-all\\-ssg\\/(.+?)\\.json$`,
)}\\/p1\\/p2\\/nested\\-all\\-ssg\\/(.+?)\\.json$`
),
page: '/p1/p2/nested-all-ssg/[...rest]', page: '/p1/p2/nested-all-ssg/[...rest]',
routeKeys: { routeKeys: {
nxtPrest: 'nxtPrest', nxtPrest: 'nxtPrest',
...@@ -1329,22 +1326,18 @@ function runTests({ dev }) { ...@@ -1329,22 +1326,18 @@ function runTests({ dev }) {
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId buildId
)}/p1/p2/predefined\\-ssg/(?<nxtPrest>.+?)\\.json$`, )}/p1/p2/predefined\\-ssg/(?<nxtPrest>.+?)\\.json$`,
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
`^\\/_next\\/data\\/${escapeRegex( buildId
buildId )}\\/p1\\/p2\\/predefined\\-ssg\\/(.+?)\\.json$`,
)}\\/p1\\/p2\\/predefined\\-ssg\\/(.+?)\\.json$`
),
page: '/p1/p2/predefined-ssg/[...rest]', page: '/p1/p2/predefined-ssg/[...rest]',
routeKeys: { routeKeys: {
nxtPrest: 'nxtPrest', nxtPrest: 'nxtPrest',
}, },
}, },
{ {
dataRouteRegex: normalizeRegEx( dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
`^\\/_next\\/data\\/${escapeRegex( buildId
buildId )}\\/([^\\/]+?)\\/([^\\/]+?)\\/(.+?)\\.json$`,
)}\\/([^\\/]+?)\\/([^\\/]+?)\\/(.+?)\\.json$`
),
namedDataRouteRegex: `^/_next/data/${escapeRegex( namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId buildId
)}/(?<nxtPname>[^/]+?)/(?<nxtPcomment>[^/]+?)/(?<nxtPrest>.+?)\\.json$`, )}/(?<nxtPname>[^/]+?)/(?<nxtPcomment>[^/]+?)/(?<nxtPrest>.+?)\\.json$`,
...@@ -1355,12 +1348,12 @@ function runTests({ dev }) { ...@@ -1355,12 +1348,12 @@ function runTests({ dev }) {
nxtPrest: 'nxtPrest', nxtPrest: 'nxtPrest',
}, },
}, },
], ].map((item) => normalizeRouteRegExes(item)),
dynamicRoutes: [ dynamicRoutes: [
{ {
namedRegex: '^/b/(?<nxtP123>[^/]+?)(?:/)?$', namedRegex: '^/b/(?<nxtP123>[^/]+?)(?:/)?$',
page: '/b/[123]', page: '/b/[123]',
regex: normalizeRegEx('^\\/b\\/([^\\/]+?)(?:\\/)?$'), regex: '^\\/b\\/([^\\/]+?)(?:\\/)?$',
routeKeys: { routeKeys: {
nxtP123: 'nxtP123', nxtP123: 'nxtP123',
}, },
...@@ -1368,9 +1361,7 @@ function runTests({ dev }) { ...@@ -1368,9 +1361,7 @@ function runTests({ dev }) {
{ {
namedRegex: `^/blog/(?<nxtPname>[^/]+?)/comment/(?<nxtPid>[^/]+?)(?:/)?$`, namedRegex: `^/blog/(?<nxtPname>[^/]+?)/comment/(?<nxtPid>[^/]+?)(?:/)?$`,
page: '/blog/[name]/comment/[id]', page: '/blog/[name]/comment/[id]',
regex: normalizeRegEx( regex: '^\\/blog\\/([^\\/]+?)\\/comment\\/([^\\/]+?)(?:\\/)?$',
'^\\/blog\\/([^\\/]+?)\\/comment\\/([^\\/]+?)(?:\\/)?$'
),
routeKeys: { routeKeys: {
nxtPname: 'nxtPname', nxtPname: 'nxtPname',
nxtPid: 'nxtPid', nxtPid: 'nxtPid',
...@@ -1379,7 +1370,7 @@ function runTests({ dev }) { ...@@ -1379,7 +1370,7 @@ function runTests({ dev }) {
{ {
namedRegex: '^/c/(?<a>[^/]+?)(?:/)?$', namedRegex: '^/c/(?<a>[^/]+?)(?:/)?$',
page: '/c/[alongparamnameshouldbeallowedeventhoughweird]', page: '/c/[alongparamnameshouldbeallowedeventhoughweird]',
regex: normalizeRegEx('^\\/c\\/([^\\/]+?)(?:\\/)?$'), regex: '^\\/c\\/([^\\/]+?)(?:\\/)?$',
routeKeys: { routeKeys: {
a: 'nxtPalongparamnameshouldbeallowedeventhoughweird', a: 'nxtPalongparamnameshouldbeallowedeventhoughweird',
}, },
...@@ -1387,7 +1378,7 @@ function runTests({ dev }) { ...@@ -1387,7 +1378,7 @@ function runTests({ dev }) {
{ {
namedRegex: '^/catchall\\-dash/(?<nxtPhelloworld>.+?)(?:/)?$', namedRegex: '^/catchall\\-dash/(?<nxtPhelloworld>.+?)(?:/)?$',
page: '/catchall-dash/[...hello-world]', page: '/catchall-dash/[...hello-world]',
regex: normalizeRegEx('^\\/catchall\\-dash\\/(.+?)(?:\\/)?$'), regex: '^\\/catchall\\-dash\\/(.+?)(?:\\/)?$',
routeKeys: { routeKeys: {
nxtPhelloworld: 'nxtPhello-world', nxtPhelloworld: 'nxtPhello-world',
}, },
...@@ -1395,7 +1386,7 @@ function runTests({ dev }) { ...@@ -1395,7 +1386,7 @@ function runTests({ dev }) {
{ {
namedRegex: '^/d/(?<nxtPid>[^/]+?)(?:/)?$', namedRegex: '^/d/(?<nxtPid>[^/]+?)(?:/)?$',
page: '/d/[id]', page: '/d/[id]',
regex: normalizeRegEx('^\\/d\\/([^\\/]+?)(?:\\/)?$'), regex: '^\\/d\\/([^\\/]+?)(?:\\/)?$',
routeKeys: { routeKeys: {
nxtPid: 'nxtPid', nxtPid: 'nxtPid',
}, },
...@@ -1403,7 +1394,7 @@ function runTests({ dev }) { ...@@ -1403,7 +1394,7 @@ function runTests({ dev }) {
{ {
namedRegex: '^/dash/(?<nxtPhelloworld>[^/]+?)(?:/)?$', namedRegex: '^/dash/(?<nxtPhelloworld>[^/]+?)(?:/)?$',
page: '/dash/[hello-world]', page: '/dash/[hello-world]',
regex: normalizeRegEx('^\\/dash\\/([^\\/]+?)(?:\\/)?$'), regex: '^\\/dash\\/([^\\/]+?)(?:\\/)?$',
routeKeys: { routeKeys: {
nxtPhelloworld: 'nxtPhello-world', nxtPhelloworld: 'nxtPhello-world',
}, },
...@@ -1411,7 +1402,7 @@ function runTests({ dev }) { ...@@ -1411,7 +1402,7 @@ function runTests({ dev }) {
{ {
namedRegex: '^/index/(?<nxtPslug>.+?)(?:/)?$', namedRegex: '^/index/(?<nxtPslug>.+?)(?:/)?$',
page: '/index/[...slug]', page: '/index/[...slug]',
regex: normalizeRegEx('^/index/(.+?)(?:/)?$'), regex: '^/index/(.+?)(?:/)?$',
routeKeys: { routeKeys: {
nxtPslug: 'nxtPslug', nxtPslug: 'nxtPslug',
}, },
...@@ -1419,7 +1410,7 @@ function runTests({ dev }) { ...@@ -1419,7 +1410,7 @@ function runTests({ dev }) {
{ {
namedRegex: `^/on\\-mount/(?<nxtPpost>[^/]+?)(?:/)?$`, namedRegex: `^/on\\-mount/(?<nxtPpost>[^/]+?)(?:/)?$`,
page: '/on-mount/[post]', page: '/on-mount/[post]',
regex: normalizeRegEx('^\\/on\\-mount\\/([^\\/]+?)(?:\\/)?$'), regex: '^\\/on\\-mount\\/([^\\/]+?)(?:\\/)?$',
routeKeys: { routeKeys: {
nxtPpost: 'nxtPpost', nxtPpost: 'nxtPpost',
}, },
...@@ -1427,7 +1418,7 @@ function runTests({ dev }) { ...@@ -1427,7 +1418,7 @@ function runTests({ dev }) {
{ {
namedRegex: `^/p1/p2/all\\-ssg/(?<nxtPrest>.+?)(?:/)?$`, namedRegex: `^/p1/p2/all\\-ssg/(?<nxtPrest>.+?)(?:/)?$`,
page: '/p1/p2/all-ssg/[...rest]', page: '/p1/p2/all-ssg/[...rest]',
regex: normalizeRegEx('^\\/p1\\/p2\\/all\\-ssg\\/(.+?)(?:\\/)?$'), regex: '^\\/p1\\/p2\\/all\\-ssg\\/(.+?)(?:\\/)?$',
routeKeys: { routeKeys: {
nxtPrest: 'nxtPrest', nxtPrest: 'nxtPrest',
}, },
...@@ -1435,7 +1426,7 @@ function runTests({ dev }) { ...@@ -1435,7 +1426,7 @@ function runTests({ dev }) {
{ {
namedRegex: `^/p1/p2/all\\-ssr/(?<nxtPrest>.+?)(?:/)?$`, namedRegex: `^/p1/p2/all\\-ssr/(?<nxtPrest>.+?)(?:/)?$`,
page: '/p1/p2/all-ssr/[...rest]', page: '/p1/p2/all-ssr/[...rest]',
regex: normalizeRegEx('^\\/p1\\/p2\\/all\\-ssr\\/(.+?)(?:\\/)?$'), regex: '^\\/p1\\/p2\\/all\\-ssr\\/(.+?)(?:\\/)?$',
routeKeys: { routeKeys: {
nxtPrest: 'nxtPrest', nxtPrest: 'nxtPrest',
}, },
...@@ -1443,9 +1434,7 @@ function runTests({ dev }) { ...@@ -1443,9 +1434,7 @@ function runTests({ dev }) {
{ {
namedRegex: `^/p1/p2/nested\\-all\\-ssg/(?<nxtPrest>.+?)(?:/)?$`, namedRegex: `^/p1/p2/nested\\-all\\-ssg/(?<nxtPrest>.+?)(?:/)?$`,
page: '/p1/p2/nested-all-ssg/[...rest]', page: '/p1/p2/nested-all-ssg/[...rest]',
regex: normalizeRegEx( regex: '^\\/p1\\/p2\\/nested\\-all\\-ssg\\/(.+?)(?:\\/)?$',
'^\\/p1\\/p2\\/nested\\-all\\-ssg\\/(.+?)(?:\\/)?$'
),
routeKeys: { routeKeys: {
nxtPrest: 'nxtPrest', nxtPrest: 'nxtPrest',
}, },
...@@ -1453,9 +1442,7 @@ function runTests({ dev }) { ...@@ -1453,9 +1442,7 @@ function runTests({ dev }) {
{ {
namedRegex: `^/p1/p2/predefined\\-ssg/(?<nxtPrest>.+?)(?:/)?$`, namedRegex: `^/p1/p2/predefined\\-ssg/(?<nxtPrest>.+?)(?:/)?$`,
page: '/p1/p2/predefined-ssg/[...rest]', page: '/p1/p2/predefined-ssg/[...rest]',
regex: normalizeRegEx( regex: '^\\/p1\\/p2\\/predefined\\-ssg\\/(.+?)(?:\\/)?$',
'^\\/p1\\/p2\\/predefined\\-ssg\\/(.+?)(?:\\/)?$'
),
routeKeys: { routeKeys: {
nxtPrest: 'nxtPrest', nxtPrest: 'nxtPrest',
}, },
...@@ -1463,7 +1450,7 @@ function runTests({ dev }) { ...@@ -1463,7 +1450,7 @@ function runTests({ dev }) {
{ {
namedRegex: `^/(?<nxtPname>[^/]+?)(?:/)?$`, namedRegex: `^/(?<nxtPname>[^/]+?)(?:/)?$`,
page: '/[name]', page: '/[name]',
regex: normalizeRegEx('^\\/([^\\/]+?)(?:\\/)?$'), regex: '^\\/([^\\/]+?)(?:\\/)?$',
routeKeys: { routeKeys: {
nxtPname: 'nxtPname', nxtPname: 'nxtPname',
}, },
...@@ -1471,7 +1458,7 @@ function runTests({ dev }) { ...@@ -1471,7 +1458,7 @@ function runTests({ dev }) {
{ {
namedRegex: `^/(?<nxtPname>[^/]+?)/comments(?:/)?$`, namedRegex: `^/(?<nxtPname>[^/]+?)/comments(?:/)?$`,
page: '/[name]/comments', page: '/[name]/comments',
regex: normalizeRegEx('^\\/([^\\/]+?)\\/comments(?:\\/)?$'), regex: '^\\/([^\\/]+?)\\/comments(?:\\/)?$',
routeKeys: { routeKeys: {
nxtPname: 'nxtPname', nxtPname: 'nxtPname',
}, },
...@@ -1479,9 +1466,7 @@ function runTests({ dev }) { ...@@ -1479,9 +1466,7 @@ function runTests({ dev }) {
{ {
namedRegex: `^/(?<nxtPname>[^/]+?)/on\\-mount\\-redir(?:/)?$`, namedRegex: `^/(?<nxtPname>[^/]+?)/on\\-mount\\-redir(?:/)?$`,
page: '/[name]/on-mount-redir', page: '/[name]/on-mount-redir',
regex: normalizeRegEx( regex: '^\\/([^\\/]+?)\\/on\\-mount\\-redir(?:\\/)?$',
'^\\/([^\\/]+?)\\/on\\-mount\\-redir(?:\\/)?$'
),
routeKeys: { routeKeys: {
nxtPname: 'nxtPname', nxtPname: 'nxtPname',
}, },
...@@ -1489,7 +1474,7 @@ function runTests({ dev }) { ...@@ -1489,7 +1474,7 @@ function runTests({ dev }) {
{ {
namedRegex: `^/(?<nxtPname>[^/]+?)/(?<nxtPcomment>[^/]+?)(?:/)?$`, namedRegex: `^/(?<nxtPname>[^/]+?)/(?<nxtPcomment>[^/]+?)(?:/)?$`,
page: '/[name]/[comment]', page: '/[name]/[comment]',
regex: normalizeRegEx('^\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$'), regex: '^\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$',
routeKeys: { routeKeys: {
nxtPname: 'nxtPname', nxtPname: 'nxtPname',
nxtPcomment: 'nxtPcomment', nxtPcomment: 'nxtPcomment',
...@@ -1499,16 +1484,14 @@ function runTests({ dev }) { ...@@ -1499,16 +1484,14 @@ function runTests({ dev }) {
namedRegex: namedRegex:
'^/(?<nxtPname>[^/]+?)/(?<nxtPcomment>[^/]+?)/(?<nxtPrest>.+?)(?:/)?$', '^/(?<nxtPname>[^/]+?)/(?<nxtPcomment>[^/]+?)/(?<nxtPrest>.+?)(?:/)?$',
page: '/[name]/[comment]/[...rest]', page: '/[name]/[comment]/[...rest]',
regex: normalizeRegEx( regex: '^\\/([^\\/]+?)\\/([^\\/]+?)\\/(.+?)(?:\\/)?$',
'^\\/([^\\/]+?)\\/([^\\/]+?)\\/(.+?)(?:\\/)?$'
),
routeKeys: { routeKeys: {
nxtPcomment: 'nxtPcomment', nxtPcomment: 'nxtPcomment',
nxtPname: 'nxtPname', nxtPname: 'nxtPname',
nxtPrest: 'nxtPrest', nxtPrest: 'nxtPrest',
}, },
}, },
], ].map((item) => normalizeRouteRegExes(item)),
rsc: { rsc: {
header: 'RSC', header: 'RSC',
contentTypeHeader: 'text/x-component', contentTypeHeader: 'text/x-component',
......
...@@ -12,8 +12,8 @@ import { ...@@ -12,8 +12,8 @@ import {
fetchViaHTTP, fetchViaHTTP,
renderViaHTTP, renderViaHTTP,
waitFor, waitFor,
normalizeRegEx,
check, check,
normalizeRouteRegExes,
} from 'next-test-utils' } from 'next-test-utils'
const domainLocales = ['go', 'go-BE', 'do', 'do-BE'] const domainLocales = ['go', 'go-BE', 'do', 'do-BE']
...@@ -767,9 +767,7 @@ export function runTests(ctx) { ...@@ -767,9 +767,7 @@ export function runTests(ctx) {
for (const key of Object.keys(prerenderManifest.dynamicRoutes).sort()) { for (const key of Object.keys(prerenderManifest.dynamicRoutes).sort()) {
const item = prerenderManifest.dynamicRoutes[key] const item = prerenderManifest.dynamicRoutes[key]
item.routeRegex = normalizeRegEx(item.routeRegex) dynamicRoutes[key] = normalizeRouteRegExes(item)
item.dataRouteRegex = normalizeRegEx(item.dataRouteRegex)
dynamicRoutes[key] = item
} }
expect( expect(
...@@ -1167,25 +1165,25 @@ export function runTests(ctx) { ...@@ -1167,25 +1165,25 @@ export function runTests(ctx) {
).toMatchInlineSnapshot(` ).toMatchInlineSnapshot(`
"{ "{
"/gsp/fallback/[slug]": { "/gsp/fallback/[slug]": {
"routeRegex": "^\\/gsp\\/fallback\\/([^\\/]+?)(?:\\/)?$", "routeRegex": "^\\/gsp\\/fallback\\/([^\\/]+?)?$",
"dataRoute": "/_next/data/BUILD_ID/gsp/fallback/[slug].json", "dataRoute": "/_next/data/BUILD_ID/gsp/fallback/[slug].json",
"fallback": "/gsp/fallback/[slug].html", "fallback": "/gsp/fallback/[slug].html",
"dataRouteRegex": "^\\/_next\\/data\\/BUILD_ID\\/gsp\\/fallback\\/([^\\/]+?)\\.json$" "dataRouteRegex": "^\\/_next\\/data\\/BUILD_ID\\/gsp\\/fallback\\/([^\\/]+?)\\.json$"
}, },
"/gsp/no-fallback/[slug]": { "/gsp/no-fallback/[slug]": {
"routeRegex": "^\\/gsp\\/no\\-fallback\\/([^\\/]+?)(?:\\/)?$", "routeRegex": "^\\/gsp\\/no\\-fallback\\/([^\\/]+?)?$",
"dataRoute": "/_next/data/BUILD_ID/gsp/no-fallback/[slug].json", "dataRoute": "/_next/data/BUILD_ID/gsp/no-fallback/[slug].json",
"fallback": false, "fallback": false,
"dataRouteRegex": "^\\/_next\\/data\\/BUILD_ID\\/gsp\\/no\\-fallback\\/([^\\/]+?)\\.json$" "dataRouteRegex": "^\\/_next\\/data\\/BUILD_ID\\/gsp\\/no\\-fallback\\/([^\\/]+?)\\.json$"
}, },
"/not-found/blocking-fallback/[slug]": { "/not-found/blocking-fallback/[slug]": {
"routeRegex": "^\\/not\\-found\\/blocking\\-fallback\\/([^\\/]+?)(?:\\/)?$", "routeRegex": "^\\/not\\-found\\/blocking\\-fallback\\/([^\\/]+?)?$",
"dataRoute": "/_next/data/BUILD_ID/not-found/blocking-fallback/[slug].json", "dataRoute": "/_next/data/BUILD_ID/not-found/blocking-fallback/[slug].json",
"fallback": null, "fallback": null,
"dataRouteRegex": "^\\/_next\\/data\\/BUILD_ID\\/not\\-found\\/blocking\\-fallback\\/([^\\/]+?)\\.json$" "dataRouteRegex": "^\\/_next\\/data\\/BUILD_ID\\/not\\-found\\/blocking\\-fallback\\/([^\\/]+?)\\.json$"
}, },
"/not-found/fallback/[slug]": { "/not-found/fallback/[slug]": {
"routeRegex": "^\\/not\\-found\\/fallback\\/([^\\/]+?)(?:\\/)?$", "routeRegex": "^\\/not\\-found\\/fallback\\/([^\\/]+?)?$",
"dataRoute": "/_next/data/BUILD_ID/not-found/fallback/[slug].json", "dataRoute": "/_next/data/BUILD_ID/not-found/fallback/[slug].json",
"fallback": "/not-found/fallback/[slug].html", "fallback": "/not-found/fallback/[slug].html",
"dataRouteRegex": "^\\/_next\\/data\\/BUILD_ID\\/not\\-found\\/fallback\\/([^\\/]+?)\\.json$" "dataRouteRegex": "^\\/_next\\/data\\/BUILD_ID\\/not\\-found\\/fallback\\/([^\\/]+?)\\.json$"
......
...@@ -839,7 +839,32 @@ export function getBrowserBodyText(browser: BrowserInterface) { ...@@ -839,7 +839,32 @@ export function getBrowserBodyText(browser: BrowserInterface) {
} }
export function normalizeRegEx(src: string) { export function normalizeRegEx(src: string) {
return new RegExp(src).source.replace(/\^\//g, '^\\/') return (
new RegExp(src).source
.replace(/\^\//g, '^\\/')
// normalize our ignores at the top-level so each
// snapshot doesn't need to be updated each time
.replace('(?!\\/_next\\/static)', '')
.replace('?(?:\\/)?$', '?$')
.replace('(?:\\/)?$', '?$')
)
}
export const normalizeRouteRegExes = (item: any) => {
const fields = [
'regex',
'routeRegex',
'namedRegex',
'namedDataRouteRegex',
'dataRouteRegex',
]
for (const field of fields) {
if (typeof item[field] === 'string') {
item[field] = normalizeRegEx(item[field])
}
}
return item
} }
function readJson(path: string) { function readJson(path: string) {
......
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