Unverified Commit c5159826 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Leverage blocked page for _error (#26748)



## Enhance

simplify detection for visiting `_error`

x-ref: #26610
parent be60ef52
......@@ -1447,7 +1447,6 @@ export default class Server {
): Promise<string | null> {
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)) {
......
......@@ -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'
......
......@@ -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')
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment