From 8f08bcbfb2ff5f72286a5ecbffe43b89f21a18d4 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Wed, 30 Jun 2021 13:42:36 +0800 Subject: [PATCH 1/3] Leverage blocked page for _error --- packages/next/server/next-server.ts | 5 ----- packages/next/shared/lib/constants.ts | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/next/server/next-server.ts b/packages/next/server/next-server.ts index 32ef98432e60c..55b85314b1f32 100644 --- a/packages/next/server/next-server.ts +++ b/packages/next/server/next-server.ts @@ -1446,7 +1446,6 @@ export default class Server { ): Promise { const is404Page = pathname === '/404' const is500Page = pathname === '/500' - const isErrorPage = pathname === '/_error' const isLikeServerless = typeof components.Component === 'object' && @@ -1465,10 +1464,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' From 35d1ed628e831331a45901ba76a394422dde1c29 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Thu, 1 Jul 2021 01:06:18 +0800 Subject: [PATCH 2/3] add test status code --- test/integration/client-navigation/test/index.test.js | 2 ++ 1 file changed, 2 insertions(+) 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') }) From 246073f5f706f8ad6bcd72b59215894dc24fd7a3 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Thu, 1 Jul 2021 02:10:38 +0800 Subject: [PATCH 3/3] fix test --- test/integration/size-limit/test/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/size-limit/test/index.test.js b/test/integration/size-limit/test/index.test.js index fde2f15a6df76..ca9b2f6520472 100644 --- a/test/integration/size-limit/test/index.test.js +++ b/test/integration/size-limit/test/index.test.js @@ -85,6 +85,6 @@ describe('Production response size', () => { const delta = responseSizesBytes / 1024 // Expected difference: < 0.5 - expect(delta).toBeCloseTo(286.8, 0) + expect(delta).toBeCloseTo(286.3, 0) }) })