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

Make sure to not show _error without 404 warning in some cases #12061

Merged
merged 2 commits into from
Apr 21, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/next/next-server/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,8 @@ export default class Server {
if (
process.env.NODE_ENV !== 'production' &&
!using404Page &&
(await this.hasPage('/_error'))
(await this.hasPage('/_error')) &&
!(await this.hasPage('/404'))
) {
this.customErrorNo404Warn()
}
Expand Down
25 changes: 24 additions & 1 deletion test/integration/custom-error/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
const appDir = join(__dirname, '..')
const page404 = join(appDir, 'pages/404.js')
const nextConfig = join(appDir, 'next.config.js')
let appPort
let app
Expand All @@ -27,6 +28,29 @@ const runTests = () => {
const customErrNo404Match = /You have added a custom \/_error page without a custom \/404 page/

describe('Custom _error', () => {
describe('dev mode', () => {
let stderr = ''

beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr(msg) {
stderr += msg || ''
},
})
})
afterAll(() => killApp())

it('should not warn with /_error and /404 when rendering error first', async () => {
stderr = ''
await fs.writeFile(page404, 'export default <h1>')
const html = await renderViaHTTP(appPort, '/404')
await fs.remove(page404)
expect(html).toContain('Module build failed')
expect(stderr).not.toMatch(customErrNo404Match)
})
})

describe('dev mode', () => {
let stderr = ''

Expand All @@ -42,7 +66,6 @@ describe('Custom _error', () => {

it('should not warn with /_error and /404', async () => {
stderr = ''
const page404 = join(appDir, 'pages/404.js')
await fs.writeFile(page404, `export default () => 'not found...'`)
const html = await renderViaHTTP(appPort, '/404')
await fs.remove(page404)
Expand Down