Unverified Commit b944b06f authored by Jan Varho's avatar Jan Varho Committed by GitHub

Fix notFound false pages returning 404 (#19861)

Currently pages with `notFound: false` from `getServerSideProps` behave the same as `notFound: true`, i.e. just having the key is enough to result in a 404. This fixes the check in render.tsx and adds tests for it.
parent 5678d24f
...@@ -837,7 +837,7 @@ export async function renderToHTML( ...@@ -837,7 +837,7 @@ export async function renderToHTML(
throw new Error(invalidKeysMsg('getServerSideProps', invalidKeys)) throw new Error(invalidKeysMsg('getServerSideProps', invalidKeys))
} }
if ('notFound' in data) { if ('notFound' in data && data.notFound) {
if (pathname === '/404') { if (pathname === '/404') {
throw new Error( throw new Error(
`The /404 page can not return notFound in "getStaticProps", please remove it to continue!` `The /404 page can not return notFound in "getStaticProps", please remove it to continue!`
......
...@@ -27,6 +27,7 @@ export const getServerSideProps = ({ query }) => { ...@@ -27,6 +27,7 @@ export const getServerSideProps = ({ query }) => {
} }
return { return {
notFound: false,
props: { props: {
hello: 'world', hello: 'world',
}, },
......
...@@ -27,6 +27,7 @@ export const getServerSideProps = ({ query }) => { ...@@ -27,6 +27,7 @@ export const getServerSideProps = ({ query }) => {
} }
return { return {
notFound: false,
props: { props: {
hello: 'world', hello: 'world',
}, },
......
...@@ -253,6 +253,12 @@ const navigateTest = (dev = false) => { ...@@ -253,6 +253,12 @@ const navigateTest = (dev = false) => {
const runTests = (dev = false) => { const runTests = (dev = false) => {
navigateTest(dev) navigateTest(dev)
it('should render correctly when notFound is false (non-dynamic)', async () => {
const res = await fetchViaHTTP(appPort, '/not-found')
expect(res.status).toBe(200)
})
it('should render 404 correctly when notFound is returned (non-dynamic)', async () => { it('should render 404 correctly when notFound is returned (non-dynamic)', async () => {
const res = await fetchViaHTTP(appPort, '/not-found', { hiding: true }) const res = await fetchViaHTTP(appPort, '/not-found', { hiding: true })
...@@ -274,6 +280,12 @@ const runTests = (dev = false) => { ...@@ -274,6 +280,12 @@ const runTests = (dev = false) => {
expect(await browser.eval('window.beforeNav')).toBe(1) expect(await browser.eval('window.beforeNav')).toBe(1)
}) })
it('should render correctly when notFound is false (dynamic)', async () => {
const res = await fetchViaHTTP(appPort, '/not-found/first')
expect(res.status).toBe(200)
})
it('should render 404 correctly when notFound is returned (dynamic)', async () => { it('should render 404 correctly when notFound is returned (dynamic)', async () => {
const res = await fetchViaHTTP(appPort, '/not-found/first', { const res = await fetchViaHTTP(appPort, '/not-found/first', {
hiding: true, hiding: true,
......
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