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

Fix useStatic404 condition #35749

Merged
merged 5 commits into from Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/next/build/index.ts
Expand Up @@ -1394,9 +1394,7 @@ export default async function build(
// Since custom _app.js can wrap the 404 page we have to opt-out of static optimization if it has getInitialProps
// Only export the static 404 when there is no /_error present
const useStatic404 =
!hasConcurrentFeatures &&
!customAppGetInitialProps &&
(!hasNonStaticErrorPage || hasPages404)
!customAppGetInitialProps && (!hasNonStaticErrorPage || hasPages404)

if (invalidPages.size > 0) {
const err = new Error(
Expand Down
8 changes: 8 additions & 0 deletions test/production/react-18-streaming-ssr/index.test.ts
Expand Up @@ -38,6 +38,14 @@ describe('react 18 streaming SSR in minimal mode', () => {
const html = await renderViaHTTP(next.url, '/')
expect(html).toContain('static streaming')
})

it('should have generated a static 404 page', async () => {
expect(await next.readFile('.next/server/pages/404.html')).toBeTruthy()

const res = await fetchViaHTTP(next.url, '/non-existent')
expect(res.status).toBe(404)
expect(await res.text()).toContain('This page could not be found')
})
})

describe('react 18 streaming SSR with custom next configs', () => {
Expand Down