From 9e5ee7f3d31e6a08061968347245236d64e6adf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Thu, 15 Sep 2022 20:46:28 +0200 Subject: [PATCH 1/4] fix: handle `notFound: true` in `/` with `next export` --- packages/next/export/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/next/export/index.ts b/packages/next/export/index.ts index e5c56a41e6aee63..6cf34dacc20edf7 100644 --- a/packages/next/export/index.ts +++ b/packages/next/export/index.ts @@ -643,7 +643,11 @@ export default async function exportApp( // returning notFound: true from getStaticProps will not // output html/json files during the build - if (prerenderManifest!.notFoundRoutes.includes(route)) { + if ( + prerenderManifest!.notFoundRoutes.includes(route) || + (prerenderManifest!.notFoundRoutes.includes('/') && + route === '/index') + ) { return } From c09139a89cac9a3d673f10bcf8e529656b7c8372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Thu, 15 Sep 2022 20:55:44 +0200 Subject: [PATCH 2/4] add test --- .../export-index-not-found-gsp/pages/index.js | 5 +++++ .../test/index.test.ts | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 test/integration/export-index-not-found-gsp/pages/index.js create mode 100644 test/integration/export-index-not-found-gsp/test/index.test.ts diff --git a/test/integration/export-index-not-found-gsp/pages/index.js b/test/integration/export-index-not-found-gsp/pages/index.js new file mode 100644 index 000000000000000..92a2904b360eed0 --- /dev/null +++ b/test/integration/export-index-not-found-gsp/pages/index.js @@ -0,0 +1,5 @@ +export default function Page() {} + +export function getStaticProps() { + return { notFound: true } +} diff --git a/test/integration/export-index-not-found-gsp/test/index.test.ts b/test/integration/export-index-not-found-gsp/test/index.test.ts new file mode 100644 index 000000000000000..c915d7af1b8797e --- /dev/null +++ b/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}`) + }) +}) From c4ae548d05f07ac03b1e75607b85891eef4a6977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Thu, 15 Sep 2022 20:56:44 +0200 Subject: [PATCH 3/4] return string in page component --- test/integration/export-index-not-found-gsp/pages/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/integration/export-index-not-found-gsp/pages/index.js b/test/integration/export-index-not-found-gsp/pages/index.js index 92a2904b360eed0..f5ec69c7fffa704 100644 --- a/test/integration/export-index-not-found-gsp/pages/index.js +++ b/test/integration/export-index-not-found-gsp/pages/index.js @@ -1,4 +1,6 @@ -export default function Page() {} +export default function Page() { + return 'Hello world' +} export function getStaticProps() { return { notFound: true } From 04838bc9651de02271c5d66fe428ab42c307ebc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Thu, 15 Sep 2022 21:02:03 +0200 Subject: [PATCH 4/4] normalize after route matching --- packages/next/export/index.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/next/export/index.ts b/packages/next/export/index.ts index 6cf34dacc20edf7..df6961f05d441f3 100644 --- a/packages/next/export/index.ts +++ b/packages/next/export/index.ts @@ -639,17 +639,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) || - (prerenderManifest!.notFoundRoutes.includes('/') && - route === '/index') - ) { + if (prerenderManifest!.notFoundRoutes.includes(route)) { return } + route = normalizePagePath(route) const pagePath = getPagePath(pageName, distDir, isLikeServerless) const distPagesDir = join(