Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable static 404 config to allow static 404 page when available #10290

Merged
merged 5 commits into from Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -1084,7 +1084,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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they both have to be checked:

Suggested change
if (this.nextConfig.experimental.static404 && res.statusCode === 404) {
if (this.nextConfig.experimental.static404 && (res.statusCode === 404 || err === null)) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rendering 404 when err is null seems to break the Production Usage › should handle failed param decoding test case

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ijjk interesting! We should probably fix that later

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