Unverified Commit cade8c84 authored by Balázs Orbán's avatar Balázs Orbán Committed by GitHub

fix: handle `notFound: true` in `/` with `next export` (#40592)

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)
parent 7fba48ef
...@@ -640,13 +640,13 @@ export default async function exportApp( ...@@ -640,13 +640,13 @@ export default async function exportApp(
Object.keys(prerenderManifest.routes).map(async (route) => { Object.keys(prerenderManifest.routes).map(async (route) => {
const { srcRoute } = prerenderManifest!.routes[route] const { srcRoute } = prerenderManifest!.routes[route]
const pageName = srcRoute || route const pageName = srcRoute || route
route = normalizePagePath(route)
// returning notFound: true from getStaticProps will not // returning notFound: true from getStaticProps will not
// output html/json files during the build // output html/json files during the build
if (prerenderManifest!.notFoundRoutes.includes(route)) { if (prerenderManifest!.notFoundRoutes.includes(route)) {
return return
} }
route = normalizePagePath(route)
const pagePath = getPagePath(pageName, distDir, isLikeServerless) const pagePath = getPagePath(pageName, distDir, isLikeServerless)
const distPagesDir = join( const distPagesDir = join(
......
export default function Page() {
return 'Hello world'
}
export function getStaticProps() {
return { notFound: true }
}
/* 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}`)
})
})
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