Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit e5c6271

Browse files
authored
Leverage blocked page for _error (vercel#26748)
## Enhance simplify detection for visiting `_error` x-ref: vercel#26610
1 parent 9f16b12 commit e5c6271

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

packages/next/server/next-server.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,6 @@ export default class Server {
14471447
): Promise<string | null> {
14481448
const is404Page = pathname === '/404'
14491449
const is500Page = pathname === '/500'
1450-
const isErrorPage = pathname === '/_error'
14511450

14521451
const isLikeServerless =
14531452
typeof components.Component === 'object' &&
@@ -1466,10 +1465,6 @@ export default class Server {
14661465
res.statusCode = 404
14671466
}
14681467

1469-
if (isErrorPage && res.statusCode === 200) {
1470-
res.statusCode = 404
1471-
}
1472-
14731468
// ensure correct status is set when visiting a status page
14741469
// directly e.g. /500
14751470
if (STATIC_STATUS_PAGES.includes(pathname)) {

packages/next/shared/lib/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const SERVER_DIRECTORY = 'server'
1717
export const SERVERLESS_DIRECTORY = 'serverless'
1818
export const CONFIG_FILE = 'next.config.js'
1919
export const BUILD_ID_FILE = 'BUILD_ID'
20-
export const BLOCKED_PAGES = ['/_document', '/_app']
20+
export const BLOCKED_PAGES = ['/_document', '/_app', '/_error']
2121
export const CLIENT_PUBLIC_FILES_PATH = 'public'
2222
export const CLIENT_STATIC_FILES_PATH = 'static'
2323
export const CLIENT_STATIC_FILES_RUNTIME = 'runtime'

test/integration/client-navigation/test/index.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('Client Navigation', () => {
2929
afterAll(() => killApp(context.server))
3030

3131
it('should not reload when visiting /_error directly', async () => {
32+
const { status } = await fetchViaHTTP(context.appPort, '/_error')
3233
const browser = await webdriver(context.appPort, '/_error')
3334

3435
await browser.eval('window.hello = true')
@@ -41,6 +42,7 @@ describe('Client Navigation', () => {
4142
}
4243
const html = await browser.eval('document.documentElement.innerHTML')
4344

45+
expect(status).toBe(404)
4446
expect(html).toContain('This page could not be found')
4547
expect(html).toContain('404')
4648
})

0 commit comments

Comments
 (0)