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`. ...@@ -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 ### 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]]`). 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. 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 ...@@ -87,9 +87,6 @@ And in the case of `/post/a/b`, and any other matching path, new parameters will
### Optional catch all routes ### 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]]`). 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. For example, `pages/post/[[...slug]].js` will match `/post`, `/post/a`, `/post/a/b`, and so on.
......
...@@ -47,6 +47,7 @@ import loadConfig, { ...@@ -47,6 +47,7 @@ import loadConfig, {
import { BuildManifest } from '../next-server/server/get-page-files' import { BuildManifest } from '../next-server/server/get-page-files'
import '../next-server/server/node-polyfill-fetch' import '../next-server/server/node-polyfill-fetch'
import { normalizePagePath } from '../next-server/server/normalize-page-path' import { normalizePagePath } from '../next-server/server/normalize-page-path'
import { getPagePath } from '../next-server/server/require'
import * as ciEnvironment from '../telemetry/ci-info' import * as ciEnvironment from '../telemetry/ci-info'
import { import {
eventBuildCompleted, eventBuildCompleted,
...@@ -73,7 +74,6 @@ import { ...@@ -73,7 +74,6 @@ import {
import getBaseWebpackConfig from './webpack-config' import getBaseWebpackConfig from './webpack-config'
import { PagesManifest } from './webpack/plugins/pages-manifest-plugin' import { PagesManifest } from './webpack/plugins/pages-manifest-plugin'
import { writeBuildId } from './write-build-id' import { writeBuildId } from './write-build-id'
import { getPagePath } from '../next-server/server/require'
const staticCheckWorker = require.resolve('./utils') const staticCheckWorker = require.resolve('./utils')
export type SsgRoute = { export type SsgRoute = {
...@@ -277,16 +277,6 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -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 routesManifestPath = path.join(distDir, ROUTES_MANIFEST)
const routesManifest: any = { const routesManifest: any = {
version: 3, version: 3,
......
...@@ -2,10 +2,9 @@ import chalk from 'next/dist/compiled/chalk' ...@@ -2,10 +2,9 @@ import chalk from 'next/dist/compiled/chalk'
import findUp from 'next/dist/compiled/find-up' import findUp from 'next/dist/compiled/find-up'
import os from 'os' import os from 'os'
import { basename, extname } from 'path' import { basename, extname } from 'path'
import * as Log from '../../build/output/log'
import { CONFIG_FILE } from '../lib/constants' import { CONFIG_FILE } from '../lib/constants'
import { execOnce } from '../lib/utils' import { execOnce } from '../lib/utils'
import * as Log from '../../build/output/log'
const targets = ['server', 'serverless', 'experimental-serverless-trace'] const targets = ['server', 'serverless', 'experimental-serverless-trace']
const reactModes = ['legacy', 'blocking', 'concurrent'] const reactModes = ['legacy', 'blocking', 'concurrent']
...@@ -54,7 +53,6 @@ const defaultConfig: { [key: string]: any } = { ...@@ -54,7 +53,6 @@ const defaultConfig: { [key: string]: any } = {
workerThreads: false, workerThreads: false,
pageEnv: false, pageEnv: false,
productionBrowserSourceMaps: false, productionBrowserSourceMaps: false,
optionalCatchAll: false,
}, },
future: { future: {
excludeDefaultMomentLocales: false, excludeDefaultMomentLocales: false,
......
...@@ -210,21 +210,6 @@ export default class DevServer extends Server { ...@@ -210,21 +210,6 @@ export default class DevServer extends Server {
match: getRouteMatcher(getRouteRegex(page)), 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) this.router.setDynamicRoutes(this.dynamicRoutes)
if (!resolved) { if (!resolved) {
......
module.exports = { experimental: { optionalCatchAll: true } } module.exports = {}
...@@ -261,10 +261,7 @@ describe('Dynamic Optional Routing', () => { ...@@ -261,10 +261,7 @@ describe('Dynamic Optional Routing', () => {
const curConfig = await fs.readFile(nextConfig, 'utf8') const curConfig = await fs.readFile(nextConfig, 'utf8')
if (curConfig.includes('target')) { if (curConfig.includes('target')) {
await fs.writeFile( await fs.writeFile(nextConfig, `module.exports = {}`)
nextConfig,
`module.exports = { experimental: { optionalCatchAll: true } }`
)
} }
await nextBuild(appDir) await nextBuild(appDir)
...@@ -323,7 +320,7 @@ describe('Dynamic Optional Routing', () => { ...@@ -323,7 +320,7 @@ describe('Dynamic Optional Routing', () => {
origNextConfig = await fs.readFile(nextConfig, 'utf8') origNextConfig = await fs.readFile(nextConfig, 'utf8')
await fs.writeFile( await fs.writeFile(
nextConfig, nextConfig,
`module.exports = { target: 'serverless', experimental: { optionalCatchAll: true } }` `module.exports = { target: 'serverless' }`
) )
await nextBuild(appDir) await nextBuild(appDir)
......
module.exports = { module.exports = {
experimental: {
optionalCatchAll: true,
},
rewrites() { rewrites() {
return [ return [
{ {
......
...@@ -1330,9 +1330,6 @@ describe('SSG Prerender', () => { ...@@ -1330,9 +1330,6 @@ describe('SSG Prerender', () => {
nextConfig, nextConfig,
` `
module.exports = { module.exports = {
experimental: {
optionalCatchAll: true,
},
rewrites() { rewrites() {
return [ return [
{ {
...@@ -1372,7 +1369,7 @@ describe('SSG Prerender', () => { ...@@ -1372,7 +1369,7 @@ describe('SSG Prerender', () => {
nextConfig, nextConfig,
// we set cpus to 1 so that we make sure the requests // we set cpus to 1 so that we make sure the requests
// aren't being cached at the jest-worker level // aren't being cached at the jest-worker level
`module.exports = { experimental: { optionalCatchAll: true, cpus: 1 } }`, `module.exports = { experimental: { cpus: 1 } }`,
'utf8' 'utf8'
) )
await fs.remove(join(appDir, '.next')) await fs.remove(join(appDir, '.next'))
...@@ -1439,9 +1436,6 @@ describe('SSG Prerender', () => { ...@@ -1439,9 +1436,6 @@ describe('SSG Prerender', () => {
nextConfig, nextConfig,
`module.exports = { `module.exports = {
target: 'serverless', target: 'serverless',
experimental: {
optionalCatchAll: true,
},
rewrites() { rewrites() {
return [ return [
{ {
...@@ -1550,7 +1544,7 @@ describe('SSG Prerender', () => { ...@@ -1550,7 +1544,7 @@ describe('SSG Prerender', () => {
origConfig = await fs.readFile(nextConfig, 'utf8') origConfig = await fs.readFile(nextConfig, 'utf8')
await fs.writeFile( await fs.writeFile(
nextConfig, nextConfig,
`module.exports = { target: 'experimental-serverless-trace', experimental: { optionalCatchAll: true } }`, `module.exports = { target: 'experimental-serverless-trace' }`,
'utf8' 'utf8'
) )
await fs.writeFile( await fs.writeFile(
...@@ -1637,7 +1631,6 @@ describe('SSG Prerender', () => { ...@@ -1637,7 +1631,6 @@ describe('SSG Prerender', () => {
await fs.writeFile( await fs.writeFile(
nextConfig, nextConfig,
`module.exports = { `module.exports = {
experimental: { optionalCatchAll: true },
exportTrailingSlash: true, exportTrailingSlash: true,
exportPathMap: function(defaultPathMap) { exportPathMap: function(defaultPathMap) {
if (defaultPathMap['/blog/[post]']) { 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