Unverified Commit 1d0e7a8a authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Enable Optional Catch-All by Default (#14687)

Closes #14682
parent f12a9f92
......@@ -82,9 +82,6 @@ Now, a request to `/api/post/a/b/c` will respond with the text: `Post: a, b, c`.
### Optional catch all API routes
> **Warning**: This feature is **experimental and may not work as expected**.
> You must enable the `optionalCatchAll` experimental option to try it.
Catch all routes can be made optional by including the parameter in double brackets (`[[...slug]]`).
For example, `pages/api/post/[[...slug]].js` will match `/api/post`, `/api/post/a`, `/api/post/a/b`, and so on.
......
......@@ -87,9 +87,6 @@ And in the case of `/post/a/b`, and any other matching path, new parameters will
### Optional catch all routes
> **Warning**: This feature is **experimental and may not work as expected**.
> You must enable the `optionalCatchAll` experimental option to try it.
Catch all routes can be made optional by including the parameter in double brackets (`[[...slug]]`).
For example, `pages/post/[[...slug]].js` will match `/post`, `/post/a`, `/post/a/b`, and so on.
......
......@@ -47,6 +47,7 @@ import loadConfig, {
import { BuildManifest } from '../next-server/server/get-page-files'
import '../next-server/server/node-polyfill-fetch'
import { normalizePagePath } from '../next-server/server/normalize-page-path'
import { getPagePath } from '../next-server/server/require'
import * as ciEnvironment from '../telemetry/ci-info'
import {
eventBuildCompleted,
......@@ -73,7 +74,6 @@ import {
import getBaseWebpackConfig from './webpack-config'
import { PagesManifest } from './webpack/plugins/pages-manifest-plugin'
import { writeBuildId } from './write-build-id'
import { getPagePath } from '../next-server/server/require'
const staticCheckWorker = require.resolve('./utils')
export type SsgRoute = {
......@@ -277,16 +277,6 @@ export default async function build(dir: string, conf = null): Promise<void> {
}
}
const firstOptionalCatchAllPage =
pageKeys.find((f) => /\[\[\.{3}[^\][/]*\]\]/.test(f)) ?? null
if (
config.experimental?.optionalCatchAll !== true &&
firstOptionalCatchAllPage
) {
const msg = `Optional catch-all routes are currently experimental and cannot be used by default ("${firstOptionalCatchAllPage}").`
throw new Error(msg)
}
const routesManifestPath = path.join(distDir, ROUTES_MANIFEST)
const routesManifest: any = {
version: 3,
......
......@@ -2,10 +2,9 @@ import chalk from 'next/dist/compiled/chalk'
import findUp from 'next/dist/compiled/find-up'
import os from 'os'
import { basename, extname } from 'path'
import * as Log from '../../build/output/log'
import { CONFIG_FILE } from '../lib/constants'
import { execOnce } from '../lib/utils'
import * as Log from '../../build/output/log'
const targets = ['server', 'serverless', 'experimental-serverless-trace']
const reactModes = ['legacy', 'blocking', 'concurrent']
......@@ -54,7 +53,6 @@ const defaultConfig: { [key: string]: any } = {
workerThreads: false,
pageEnv: false,
productionBrowserSourceMaps: false,
optionalCatchAll: false,
},
future: {
excludeDefaultMomentLocales: false,
......
......@@ -210,21 +210,6 @@ export default class DevServer extends Server {
match: getRouteMatcher(getRouteRegex(page)),
}))
const firstOptionalCatchAllPage =
this.dynamicRoutes.find((f) => /\[\[\.{3}[^\][/]*\]\]/.test(f.page))
?.page ?? null
if (
this.nextConfig.experimental?.optionalCatchAll !== true &&
firstOptionalCatchAllPage
) {
const msg = `Optional catch-all routes are currently experimental and cannot be used by default ("${firstOptionalCatchAllPage}").`
if (resolved) {
console.warn(msg)
} else {
throw new Error(msg)
}
}
this.router.setDynamicRoutes(this.dynamicRoutes)
if (!resolved) {
......
module.exports = { experimental: { optionalCatchAll: true } }
module.exports = {}
......@@ -261,10 +261,7 @@ describe('Dynamic Optional Routing', () => {
const curConfig = await fs.readFile(nextConfig, 'utf8')
if (curConfig.includes('target')) {
await fs.writeFile(
nextConfig,
`module.exports = { experimental: { optionalCatchAll: true } }`
)
await fs.writeFile(nextConfig, `module.exports = {}`)
}
await nextBuild(appDir)
......@@ -323,7 +320,7 @@ describe('Dynamic Optional Routing', () => {
origNextConfig = await fs.readFile(nextConfig, 'utf8')
await fs.writeFile(
nextConfig,
`module.exports = { target: 'serverless', experimental: { optionalCatchAll: true } }`
`module.exports = { target: 'serverless' }`
)
await nextBuild(appDir)
......
module.exports = {
experimental: {
optionalCatchAll: true,
},
rewrites() {
return [
{
......
......@@ -1330,9 +1330,6 @@ describe('SSG Prerender', () => {
nextConfig,
`
module.exports = {
experimental: {
optionalCatchAll: true,
},
rewrites() {
return [
{
......@@ -1372,7 +1369,7 @@ describe('SSG Prerender', () => {
nextConfig,
// we set cpus to 1 so that we make sure the requests
// aren't being cached at the jest-worker level
`module.exports = { experimental: { optionalCatchAll: true, cpus: 1 } }`,
`module.exports = { experimental: { cpus: 1 } }`,
'utf8'
)
await fs.remove(join(appDir, '.next'))
......@@ -1439,9 +1436,6 @@ describe('SSG Prerender', () => {
nextConfig,
`module.exports = {
target: 'serverless',
experimental: {
optionalCatchAll: true,
},
rewrites() {
return [
{
......@@ -1550,7 +1544,7 @@ describe('SSG Prerender', () => {
origConfig = await fs.readFile(nextConfig, 'utf8')
await fs.writeFile(
nextConfig,
`module.exports = { target: 'experimental-serverless-trace', experimental: { optionalCatchAll: true } }`,
`module.exports = { target: 'experimental-serverless-trace' }`,
'utf8'
)
await fs.writeFile(
......@@ -1637,7 +1631,6 @@ describe('SSG Prerender', () => {
await fs.writeFile(
nextConfig,
`module.exports = {
experimental: { optionalCatchAll: true },
exportTrailingSlash: true,
exportPathMap: function(defaultPathMap) {
if (defaultPathMap['/blog/[post]']) {
......
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