Skip to content

Commit

Permalink
Enable static 404 config to allow static 404 page when availab… (#10290)
Browse files Browse the repository at this point in the history
* Enable static 404 config to allow static 404 page when available

* Update static 404 suite

* Fix invalid params test case
  • Loading branch information
ijjk authored and timneutkens committed Jan 28, 2020
1 parent bd3662b commit f711b77
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/next/next-server/server/config.ts
Expand Up @@ -52,7 +52,7 @@ const defaultConfig: { [key: string]: any } = {
reactMode: 'legacy',
workerThreads: false,
basePath: '',
static404: false,
static404: true,
},
future: {
excludeDefaultMomentLocales: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/next/next-server/server/next-server.ts
Expand Up @@ -1116,7 +1116,7 @@ export default class Server {
let result: null | LoadComponentsReturnType = null

// use static 404 page if available and is 404 response
if (this.nextConfig.experimental.static404 && err === null) {
if (this.nextConfig.experimental.static404 && res.statusCode === 404) {
try {
result = await this.findPageComponents('/_errors/404')
} catch (err) {
Expand Down
11 changes: 5 additions & 6 deletions test/integration/static-404/test/index.test.js
Expand Up @@ -20,7 +20,6 @@ const static404 = join(
const appPage = join(appDir, 'pages/_app.js')
const errorPage = join(appDir, 'pages/_error.js')
const buildId = `generateBuildId: () => 'test-id'`
const experimentalConfig = `experimental: { static404: true }`
let app
let appPort

Expand All @@ -34,18 +33,18 @@ describe('Static 404 page', () => {

describe('With config disabled', () => {
it('should not have exported static 404 page', async () => {
await fs.writeFile(nextConfig, `module.exports = { ${buildId} }`)
await fs.writeFile(
nextConfig,
`module.exports = { ${buildId}, experimental: { static404: false } }`
)
await nextBuild(appDir)
expect(await fs.exists(static404)).toBe(false)
})
})

describe('With config enabled', () => {
beforeEach(() =>
fs.writeFile(
nextConfig,
`module.exports = { ${buildId}, ${experimentalConfig} }`
)
fs.writeFile(nextConfig, `module.exports = { ${buildId} }`)
)

it('should export 404 page without custom _error', async () => {
Expand Down

0 comments on commit f711b77

Please sign in to comment.