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: handle notFound: true in / with next export #40592

Merged
merged 6 commits into from Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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}`)
})
})