Unverified Commit 91cbf9d9 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Ignore error pages for cache revalidate (#72412) (#72484)

parent 27554305
...@@ -1733,9 +1733,11 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -1733,9 +1733,11 @@ export default abstract class Server<ServerOptions extends Options = Options> {
if (pathname === UNDERSCORE_NOT_FOUND_ROUTE) { if (pathname === UNDERSCORE_NOT_FOUND_ROUTE) {
pathname = '/404' pathname = '/404'
} }
const is404Page = pathname === '/404' const isErrorPathname = pathname === '/_error'
const is404Page =
const is500Page = pathname === '/500' pathname === '/404' || (isErrorPathname && res.statusCode === 404)
const is500Page =
pathname === '/500' || (isErrorPathname && res.statusCode === 500)
const isAppPath = components.isAppPath === true const isAppPath = components.isAppPath === true
const hasServerProps = !!components.getServerSideProps const hasServerProps = !!components.getServerSideProps
......
import { nextTestSetup } from 'e2e-utils'
describe('empty-ssg-fallback', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should not cache 404 error page', async () => {
const res = await next.fetch('/any-non-existed')
expect(res.status).toBe(404)
})
})
export const getStaticPaths = async () => {
return {
paths: [],
fallback: 'blocking',
}
}
export const getStaticProps = async () => {
return {
notFound: true,
}
}
export default function Page() {
return <p>slug</p>
}
import { GetServerSidePropsContext } from 'next'
function Error({ statusCode }: { statusCode: number }) {
return <p>{statusCode ? `${statusCode} error` : '500 error'}</p>
}
export async function getServerSideProps({ res }: GetServerSidePropsContext) {
const statusCode = res ? res.statusCode : 404
return { props: { statusCode } }
}
export default Error
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