Skip to content

Commit

Permalink
fix: handle notFound: true in / with next export (#40592)
Browse files Browse the repository at this point in the history
Closes #40571

An earlier fix in #24481 did not consider the `/` case. The page path normalization method `normalizePagePath` turned `/` into `/index` and the route matching was skipped for the index route's non-existent HTML file.

## 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 `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
  • Loading branch information
balazsorban44 committed Sep 16, 2022
1 parent 7fba48e commit cade8c8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/export/index.ts
Expand Up @@ -640,13 +640,13 @@ export default async function exportApp(
Object.keys(prerenderManifest.routes).map(async (route) => {
const { srcRoute } = prerenderManifest!.routes[route]
const pageName = srcRoute || route
route = normalizePagePath(route)

// returning notFound: true from getStaticProps will not
// output html/json files during the build
if (prerenderManifest!.notFoundRoutes.includes(route)) {
return
}
route = normalizePagePath(route)

const pagePath = getPagePath(pageName, distDir, isLikeServerless)
const distPagesDir = join(
Expand Down
7 changes: 7 additions & 0 deletions test/integration/export-index-not-found-gsp/pages/index.js
@@ -0,0 +1,7 @@
export default function Page() {
return 'Hello world'
}

export function getStaticProps() {
return { notFound: true }
}
21 changes: 21 additions & 0 deletions test/integration/export-index-not-found-gsp/test/index.test.ts
@@ -0,0 +1,21 @@
/* eslint-env jest */

import fs from 'fs-extra'
import { join } from 'path'
import { nextBuild, nextExport } from 'next-test-utils'

const appDir = join(__dirname, '../')
const outdir = join(appDir, 'out')

describe('Export index page with `notFound: true` in `getStaticProps`', () => {
it('should build successfully', async () => {
await fs.remove(join(appDir, '.next'))
const { code } = await nextBuild(appDir)
if (code !== 0) throw new Error(`build failed with status ${code}`)
})

it('should export successfully', async () => {
const { code } = await nextExport(appDir, { outdir })
if (code !== 0) throw new Error(`export failed with status ${code}`)
})
})

0 comments on commit cade8c8

Please sign in to comment.