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

Ensure /404 is not exported during build un-necessarily (#22825)

This ensures we don't export `/404` during the automatic static optimization during build when the `/404` isn't static and won't be used/copied to the final output. 

x-ref: https://github.com/vercel/next.js/issues/22815
parent 3f9c469b
......@@ -388,7 +388,11 @@ export default async function exportApp(
})
)
if (!exportPathMap['/404'] && !exportPathMap['/404.html']) {
if (
!options.buildExport &&
!exportPathMap['/404'] &&
!exportPathMap['/404.html']
) {
exportPathMap['/404'] = exportPathMap['/404.html'] = {
page: '/_error',
}
......
......@@ -59,15 +59,18 @@ describe('Static 404 page', () => {
`
import Error from 'next/error'
export default class MyError extends Error {
static getInitialProps() {
static getInitialProps({ statusCode, req }) {
if (req.url === '/404' || req.url === '/404.html') {
throw new Error('exported 404 unexpectedly!!!')
}
return {
statusCode: 404
statusCode,
}
}
}
`
)
await nextBuild(appDir)
await nextBuild(appDir, undefined, { stderr: true, stdout: true })
await fs.remove(errorPage)
})
......
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