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

Leverage blocked page for _error #26748

Merged
merged 4 commits into from
Jul 1, 2021
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
5 changes: 0 additions & 5 deletions packages/next/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' &&
Expand All @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/shared/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions test/integration/client-navigation/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
})
Expand Down