Skip to content

Commit cade8c8

Browse files
fix: handle notFound: true in / with next export (vercel#40592)
Closes vercel#40571 An earlier fix in vercel#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)
1 parent 7fba48e commit cade8c8

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

packages/next/export/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -640,13 +640,13 @@ export default async function exportApp(
640640
Object.keys(prerenderManifest.routes).map(async (route) => {
641641
const { srcRoute } = prerenderManifest!.routes[route]
642642
const pageName = srcRoute || route
643-
route = normalizePagePath(route)
644643

645644
// returning notFound: true from getStaticProps will not
646645
// output html/json files during the build
647646
if (prerenderManifest!.notFoundRoutes.includes(route)) {
648647
return
649648
}
649+
route = normalizePagePath(route)
650650

651651
const pagePath = getPagePath(pageName, distDir, isLikeServerless)
652652
const distPagesDir = join(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Page() {
2+
return 'Hello world'
3+
}
4+
5+
export function getStaticProps() {
6+
return { notFound: true }
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* eslint-env jest */
2+
3+
import fs from 'fs-extra'
4+
import { join } from 'path'
5+
import { nextBuild, nextExport } from 'next-test-utils'
6+
7+
const appDir = join(__dirname, '../')
8+
const outdir = join(appDir, 'out')
9+
10+
describe('Export index page with `notFound: true` in `getStaticProps`', () => {
11+
it('should build successfully', async () => {
12+
await fs.remove(join(appDir, '.next'))
13+
const { code } = await nextBuild(appDir)
14+
if (code !== 0) throw new Error(`build failed with status ${code}`)
15+
})
16+
17+
it('should export successfully', async () => {
18+
const { code } = await nextExport(appDir, { outdir })
19+
if (code !== 0) throw new Error(`export failed with status ${code}`)
20+
})
21+
})

0 commit comments

Comments
 (0)