Unverified Commit 88f27ef9 authored by Andrew Hurle's avatar Andrew Hurle Committed by GitHub

Fix bug where returning `{ notFound: true }` from GSP broke `next export` (#24481)

* Fix bug where returning `{ notFound: true }` from GSP broke `next export`

We could just as easily omit the notFoundRoutes check, but I didn't want
to mask other potential bugs that would result in missing files

* update check

* move check
Co-authored-by: 's avatarjj@jjsweb.site <jj@jjsweb.site>
parent 2333f7c1
......@@ -627,6 +627,14 @@ 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
}
const pagePath = getPagePath(pageName, distDir, isLikeServerless)
const distPagesDir = join(
pagePath,
......@@ -638,7 +646,6 @@ export default async function exportApp(
.map(() => '..')
.join('/')
)
route = normalizePagePath(route)
const orig = join(distPagesDir, route)
const htmlDest = join(
......@@ -655,8 +662,12 @@ export default async function exportApp(
await promises.mkdir(dirname(htmlDest), { recursive: true })
await promises.mkdir(dirname(jsonDest), { recursive: true })
await promises.copyFile(`${orig}.html`, htmlDest)
await promises.copyFile(`${orig}.json`, jsonDest)
const htmlSrc = `${orig}.html`
const jsonSrc = `${orig}.json`
await promises.copyFile(htmlSrc, htmlDest)
await promises.copyFile(jsonSrc, jsonDest)
if (await exists(`${orig}.amp.html`)) {
await promises.mkdir(dirname(ampHtmlDest), { recursive: true })
......
export default () => <p id="gsp-notfound-page">GSP notFound: true</p>
export const getStaticProps = () => ({ notFound: true })
......@@ -42,6 +42,9 @@ export default () => (
<Link href="/dynamic-imports">
<a id="dynamic-imports-link">Dynamic imports page</a>
</Link>
<Link href="/gsp-notfound">
<a id="gsp-notfound-link">GSP notfound page</a>
</Link>
</div>
<p>This is the home page</p>
<style jsx>{`
......
......@@ -193,6 +193,26 @@ export default function (context) {
}
})
it('should render 404 when visiting a page that returns notFound from gsp', async () => {
let browser
try {
browser = await webdriver(context.port, '/')
const text = await browser
.elementByCss('#gsp-notfound-link')
.click()
.waitForElementByCss('pre')
.elementByCss('pre')
.text()
expect(text).toBe('Cannot GET /gsp-notfound/')
} finally {
if (browser) {
await browser.close()
}
}
})
it('should navigate even if used a button inside <Link />', async () => {
const browser = await webdriver(context.port, '/button-link')
......
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