Unverified Commit 9a0d82b4 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Clean up landed experimental flags (#10593)

* Clean up landed experimental flags

* Remove check for experimental flags from build too

* Remove /_errors/404 in favor of /404

* Remove unneeded check for pathname

* Update test paths

* Fix test

* Update test

* Remove test for disabled config

* Set pages404 always to true
Co-authored-by: 's avatarJoe Haddad <timer150@gmail.com>
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 1c64c1e9
...@@ -221,10 +221,9 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -221,10 +221,9 @@ export default async function build(dir: string, conf = null): Promise<void> {
const hasCustomErrorPage = mappedPages['/_error'].startsWith( const hasCustomErrorPage = mappedPages['/_error'].startsWith(
'private-next-pages' 'private-next-pages'
) )
const hasPages404 = const hasPages404 = Boolean(
config.experimental.pages404 && mappedPages['/404'] && mappedPages['/404'].startsWith('private-next-pages')
mappedPages['/404'] && )
mappedPages['/404'].startsWith('private-next-pages')
if (hasPublicDir) { if (hasPublicDir) {
try { try {
...@@ -285,7 +284,7 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -285,7 +284,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
const routesManifestPath = path.join(distDir, ROUTES_MANIFEST) const routesManifestPath = path.join(distDir, ROUTES_MANIFEST)
const routesManifest: any = { const routesManifest: any = {
version: 1, version: 1,
pages404: !!hasPages404, pages404: true,
basePath: config.experimental.basePath, basePath: config.experimental.basePath,
redirects: redirects.map(r => buildCustomRoute(r, 'redirect')), redirects: redirects.map(r => buildCustomRoute(r, 'redirect')),
rewrites: rewrites.map(r => buildCustomRoute(r, 'rewrite')), rewrites: rewrites.map(r => buildCustomRoute(r, 'rewrite')),
...@@ -606,8 +605,7 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -606,8 +605,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
// Since custom _app.js can wrap the 404 page we have to opt-out of static optimization if it has getInitialProps // Since custom _app.js can wrap the 404 page we have to opt-out of static optimization if it has getInitialProps
// Only export the static 404 when there is no /_error present // Only export the static 404 when there is no /_error present
const useStatic404 = const useStatic404 =
!customAppGetInitialProps && !customAppGetInitialProps && (!hasCustomErrorPage || hasPages404)
((!hasCustomErrorPage && config.experimental.static404) || hasPages404)
if (invalidPages.size > 0) { if (invalidPages.size > 0) {
throw new Error( throw new Error(
...@@ -681,7 +679,7 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -681,7 +679,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
}) })
if (useStatic404) { if (useStatic404) {
defaultMap['/_errors/404'] = { defaultMap['/404'] = {
page: hasPages404 ? '/404' : '/_error', page: hasPages404 ? '/404' : '/_error',
} }
} }
...@@ -690,6 +688,7 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -690,6 +688,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
}, },
exportTrailingSlash: false, exportTrailingSlash: false,
} }
await exportApp(dir, exportOptions, exportConfig) await exportApp(dir, exportOptions, exportConfig)
// remove server bundles that were exported // remove server bundles that were exported
...@@ -726,8 +725,9 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -726,8 +725,9 @@ export default async function build(dir: string, conf = null): Promise<void> {
await fsMove(orig, dest) await fsMove(orig, dest)
} }
if (useStatic404) { // Only move /404 to /404 when there is no custom 404 as in that case we don't know about the 404 page
await moveExportedPage('/_errors/404', '/_errors/404', false, 'html') if (!hasPages404 && useStatic404) {
await moveExportedPage('/404', '/404', false, 'html')
} }
for (const page of combinedPages) { for (const page of combinedPages) {
......
...@@ -52,8 +52,6 @@ const defaultConfig: { [key: string]: any } = { ...@@ -52,8 +52,6 @@ const defaultConfig: { [key: string]: any } = {
reactMode: 'legacy', reactMode: 'legacy',
workerThreads: false, workerThreads: false,
basePath: '', basePath: '',
static404: true,
pages404: true,
}, },
future: { future: {
excludeDefaultMomentLocales: false, excludeDefaultMomentLocales: false,
......
...@@ -114,7 +114,6 @@ export default class Server { ...@@ -114,7 +114,6 @@ export default class Server {
documentMiddlewareEnabled: boolean documentMiddlewareEnabled: boolean
hasCssMode: boolean hasCssMode: boolean
dev?: boolean dev?: boolean
pages404?: boolean
} }
private compression?: Middleware private compression?: Middleware
private onErrorMiddleware?: ({ err }: { err: Error }) => Promise<void> private onErrorMiddleware?: ({ err }: { err: Error }) => Promise<void>
...@@ -162,7 +161,6 @@ export default class Server { ...@@ -162,7 +161,6 @@ export default class Server {
staticMarkup, staticMarkup,
buildId: this.buildId, buildId: this.buildId,
generateEtags, generateEtags,
pages404: this.nextConfig.experimental.pages404,
} }
// Only the `publicRuntimeConfig` key is exposed to the client side // Only the `publicRuntimeConfig` key is exposed to the client side
...@@ -866,7 +864,7 @@ export default class Server { ...@@ -866,7 +864,7 @@ export default class Server {
opts: any opts: any
): Promise<string | null> { ): Promise<string | null> {
// we need to ensure the status code if /404 is visited directly // we need to ensure the status code if /404 is visited directly
if (this.nextConfig.experimental.pages404 && pathname === '/404') { if (pathname === '/404') {
res.statusCode = 404 res.statusCode = 404
} }
...@@ -1171,22 +1169,13 @@ export default class Server { ...@@ -1171,22 +1169,13 @@ export default class Server {
) { ) {
let result: null | FindComponentsResult = null let result: null | FindComponentsResult = null
const { static404, pages404 } = this.nextConfig.experimental
const is404 = res.statusCode === 404 const is404 = res.statusCode === 404
let using404Page = false let using404Page = false
// use static 404 page if available and is 404 response // use static 404 page if available and is 404 response
if (is404) { if (is404) {
if (static404) { result = await this.findPageComponents('/404')
result = await this.findPageComponents('/_errors/404') using404Page = result !== null
}
// use 404 if /_errors/404 isn't available which occurs
// during development and when _app has getInitialProps
if (!result && pages404) {
result = await this.findPageComponents('/404')
using404Page = result !== null
}
} }
if (!result) { if (!result) {
...@@ -1220,11 +1209,8 @@ export default class Server { ...@@ -1220,11 +1209,8 @@ export default class Server {
): Promise<void> { ): Promise<void> {
const url: any = req.url const url: any = req.url
const { pathname, query } = parsedUrl ? parsedUrl : parseUrl(url, true) const { pathname, query } = parsedUrl ? parsedUrl : parseUrl(url, true)
if (!pathname) {
throw new Error('pathname is undefined')
}
res.statusCode = 404 res.statusCode = 404
return this.renderError(null, req, res, pathname, query) return this.renderError(null, req, res, pathname!, query)
} }
public async serveStatic( public async serveStatic(
......
...@@ -145,7 +145,6 @@ type RenderOpts = LoadComponentsReturnType & { ...@@ -145,7 +145,6 @@ type RenderOpts = LoadComponentsReturnType & {
documentMiddlewareEnabled?: boolean documentMiddlewareEnabled?: boolean
isDataReq?: boolean isDataReq?: boolean
params?: ParsedUrlQuery params?: ParsedUrlQuery
pages404?: boolean
previewProps: __ApiPreviewProps previewProps: __ApiPreviewProps
} }
...@@ -278,7 +277,6 @@ export async function renderToHTML( ...@@ -278,7 +277,6 @@ export async function renderToHTML(
unstable_getServerProps, unstable_getServerProps,
isDataReq, isDataReq,
params, params,
pages404,
previewProps, previewProps,
} = renderOpts } = renderOpts
...@@ -391,7 +389,7 @@ export async function renderToHTML( ...@@ -391,7 +389,7 @@ export async function renderToHTML(
renderOpts.nextExport = true renderOpts.nextExport = true
} }
if (pages404 && pathname === '/404' && !isAutoExport) { if (pathname === '/404' && !isAutoExport) {
throw new Error(PAGES_404_GET_INITIAL_PROPS_ERROR) throw new Error(PAGES_404_GET_INITIAL_PROPS_ERROR)
} }
} }
......
...@@ -463,13 +463,11 @@ export default class DevServer extends Server { ...@@ -463,13 +463,11 @@ export default class DevServer extends Server {
}) })
} catch (err) { } catch (err) {
if (err.code === 'ENOENT') { if (err.code === 'ENOENT') {
if (this.nextConfig.experimental.pages404) { try {
try { await this.hotReloader!.ensurePage('/404')
await this.hotReloader!.ensurePage('/404') } catch (err) {
} catch (err) { if (err.code !== 'ENOENT') {
if (err.code !== 'ENOENT') { throw err
throw err
}
} }
} }
......
module.exports = { module.exports = {}
experimental: {
pages404: true,
},
}
...@@ -49,7 +49,7 @@ const runTests = (mode = 'server') => { ...@@ -49,7 +49,7 @@ const runTests = (mode = 'server') => {
}) })
if (mode !== 'dev') { if (mode !== 'dev') {
it('should output _errors/404.html during build', async () => { it('should output 404.html during build', async () => {
expect( expect(
await fs.exists( await fs.exists(
join( join(
...@@ -58,17 +58,17 @@ const runTests = (mode = 'server') => { ...@@ -58,17 +58,17 @@ const runTests = (mode = 'server') => {
mode === 'serverless' mode === 'serverless'
? 'serverless/pages' ? 'serverless/pages'
: `server/static/${buildId}/pages`, : `server/static/${buildId}/pages`,
'_errors/404.html' '404.html'
) )
) )
).toBe(true) ).toBe(true)
}) })
it('should add _errors/404 to pages-manifest correctly', async () => { it('should add /404 to pages-manifest correctly', async () => {
const manifest = await fs.readJSON( const manifest = await fs.readJSON(
join(appDir, '.next', mode, 'pages-manifest.json') join(appDir, '.next', mode, 'pages-manifest.json')
) )
expect('/_errors/404' in manifest).toBe(true) expect('/404' in manifest).toBe(true)
}) })
} }
} }
...@@ -104,10 +104,7 @@ describe('404 Page Support', () => { ...@@ -104,10 +104,7 @@ describe('404 Page Support', () => {
nextConfig, nextConfig,
` `
module.exports = { module.exports = {
target: 'serverless', target: 'serverless'
experimental: {
pages404: true
}
} }
` `
) )
...@@ -212,7 +209,7 @@ describe('404 Page Support', () => { ...@@ -212,7 +209,7 @@ describe('404 Page Support', () => {
it('should not output static 404 if _app has getInitialProps', async () => { it('should not output static 404 if _app has getInitialProps', async () => {
expect( expect(
await fs.exists( await fs.exists(
join(appDir, '.next/server/static', buildId, 'pages/_errors/404.html') join(appDir, '.next/server/static', buildId, 'pages/404.html')
) )
).toBe(false) ).toBe(false)
}) })
......
...@@ -344,7 +344,7 @@ const runTests = (isDev = false) => { ...@@ -344,7 +344,7 @@ const runTests = (isDev = false) => {
expect(manifest).toEqual({ expect(manifest).toEqual({
version: 1, version: 1,
pages404: false, pages404: true,
basePath: '', basePath: '',
redirects: [ redirects: [
{ {
......
...@@ -487,7 +487,7 @@ function runTests(dev) { ...@@ -487,7 +487,7 @@ function runTests(dev) {
expect(manifest).toEqual({ expect(manifest).toEqual({
version: 1, version: 1,
pages404: false, pages404: true,
basePath: '', basePath: '',
headers: [], headers: [],
rewrites: [], rewrites: [],
......
...@@ -13,10 +13,7 @@ import { ...@@ -13,10 +13,7 @@ import {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
const appDir = join(__dirname, '..') const appDir = join(__dirname, '..')
const nextConfig = join(appDir, 'next.config.js') const nextConfig = join(appDir, 'next.config.js')
const static404 = join( const static404 = join(appDir, '.next/server/static/test-id/pages/404.html')
appDir,
'.next/server/static/test-id/pages/_errors/404.html'
)
const appPage = join(appDir, 'pages/_app.js') const appPage = join(appDir, 'pages/_app.js')
const errorPage = join(appDir, 'pages/_error.js') const errorPage = join(appDir, 'pages/_error.js')
const buildId = `generateBuildId: () => 'test-id'` const buildId = `generateBuildId: () => 'test-id'`
...@@ -31,17 +28,6 @@ describe('Static 404 page', () => { ...@@ -31,17 +28,6 @@ describe('Static 404 page', () => {
}) })
beforeEach(() => fs.remove(join(appDir, '.next/server'))) beforeEach(() => fs.remove(join(appDir, '.next/server')))
describe('With config disabled', () => {
it('should not have exported static 404 page', async () => {
await fs.writeFile(
nextConfig,
`module.exports = { ${buildId}, experimental: { static404: false } }`
)
await nextBuild(appDir)
expect(await fs.exists(static404)).toBe(false)
})
})
describe('With config enabled', () => { describe('With config enabled', () => {
beforeEach(() => beforeEach(() =>
fs.writeFile(nextConfig, `module.exports = { ${buildId} }`) fs.writeFile(nextConfig, `module.exports = { ${buildId} }`)
...@@ -62,8 +48,7 @@ describe('Static 404 page', () => { ...@@ -62,8 +48,7 @@ describe('Static 404 page', () => {
nextConfig, nextConfig,
` `
module.exports = { module.exports = {
target: 'experimental-serverless-trace', target: 'experimental-serverless-trace'
experimental: { static404: true }
} }
` `
) )
...@@ -74,7 +59,7 @@ describe('Static 404 page', () => { ...@@ -74,7 +59,7 @@ describe('Static 404 page', () => {
await killApp(app) await killApp(app)
expect(html).toContain('This page could not be found') expect(html).toContain('This page could not be found')
expect( expect(
await fs.exists(join(appDir, '.next/serverless/pages/_errors/404.html')) await fs.exists(join(appDir, '.next/serverless/pages/404.html'))
).toBe(true) ).toBe(true)
}) })
......
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