Skip to content

Commit

Permalink
Fix useStatic404 condition (#35749)
Browse files Browse the repository at this point in the history
Static optimization is now supported with concurrent features, this PR fixes the condition for `useStatic404`.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
  • Loading branch information
shuding and ijjk committed Mar 30, 2022
1 parent 23be63d commit 0409b38
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
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
Expand Up @@ -113,7 +113,7 @@ describe('Without global runtime configuration', () => {
/^[┌├└/]/.test(line)
)
const expectedOutputLines = splitLines(`
λ /404
/404
├ ℇ /edge
├ ℇ /edge-rsc
├ ○ /node
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

0 comments on commit 0409b38

Please sign in to comment.