diff --git a/packages/next/server/next-server.ts b/packages/next/server/next-server.ts index 4485694598587..1ac39fb1f4637 100644 --- a/packages/next/server/next-server.ts +++ b/packages/next/server/next-server.ts @@ -1447,7 +1447,6 @@ export default class Server { ): Promise { const is404Page = pathname === '/404' const is500Page = pathname === '/500' - const isErrorPage = pathname === '/_error' const isLikeServerless = typeof components.Component === 'object' && @@ -1466,10 +1465,6 @@ export default class Server { res.statusCode = 404 } - if (isErrorPage && res.statusCode === 200) { - res.statusCode = 404 - } - // ensure correct status is set when visiting a status page // directly e.g. /500 if (STATIC_STATUS_PAGES.includes(pathname)) { diff --git a/packages/next/shared/lib/constants.ts b/packages/next/shared/lib/constants.ts index 8d2dc6ba86db4..8ea2a7d271dd9 100644 --- a/packages/next/shared/lib/constants.ts +++ b/packages/next/shared/lib/constants.ts @@ -17,7 +17,7 @@ export const SERVER_DIRECTORY = 'server' export const SERVERLESS_DIRECTORY = 'serverless' export const CONFIG_FILE = 'next.config.js' export const BUILD_ID_FILE = 'BUILD_ID' -export const BLOCKED_PAGES = ['/_document', '/_app'] +export const BLOCKED_PAGES = ['/_document', '/_app', '/_error'] export const CLIENT_PUBLIC_FILES_PATH = 'public' export const CLIENT_STATIC_FILES_PATH = 'static' export const CLIENT_STATIC_FILES_RUNTIME = 'runtime' diff --git a/test/integration/client-navigation/test/index.test.js b/test/integration/client-navigation/test/index.test.js index 678b88dda5fa3..44e5ac9283003 100644 --- a/test/integration/client-navigation/test/index.test.js +++ b/test/integration/client-navigation/test/index.test.js @@ -29,6 +29,7 @@ describe('Client Navigation', () => { afterAll(() => killApp(context.server)) it('should not reload when visiting /_error directly', async () => { + const { status } = await fetchViaHTTP(context.appPort, '/_error') const browser = await webdriver(context.appPort, '/_error') await browser.eval('window.hello = true') @@ -41,6 +42,7 @@ describe('Client Navigation', () => { } const html = await browser.eval('document.documentElement.innerHTML') + expect(status).toBe(404) expect(html).toContain('This page could not be found') expect(html).toContain('404') })