-
Notifications
You must be signed in to change notification settings - Fork 27.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dev-server): render 404 when dynamic ssg path doesn't exist (#12085)
Co-authored-by: JJ Kasper <[email protected]> Co-authored-by: Joe Haddad <[email protected]>
- Loading branch information
1 parent
5d87099
commit 47d7edd
Showing
4 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const page = () => 'custom 404 page' | ||
export default page |
6 changes: 6 additions & 0 deletions
6
test/integration/ssg-dynamic-routes-404-page/pages/post/[id].js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const getStaticPaths = async () => ({ | ||
paths: ['/post/1'], | ||
fallback: false, | ||
}) | ||
export const getStaticProps = async () => ({ props: {} }) | ||
export default () => 'blog post' |
86 changes: 86 additions & 0 deletions
86
test/integration/ssg-dynamic-routes-404-page/test/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import fs from 'fs-extra' | ||
import { join } from 'path' | ||
import { | ||
killApp, | ||
findPort, | ||
launchApp, | ||
nextStart, | ||
nextBuild, | ||
fetchViaHTTP, | ||
} from 'next-test-utils' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 | ||
|
||
const appDir = join(__dirname, '../') | ||
const nextConfig = join(appDir, 'next.config.js') | ||
|
||
let appPort | ||
let app | ||
|
||
const runTests = () => { | ||
it('should respond to a not existing page with 404', async () => { | ||
const res = await fetchViaHTTP(appPort, '/post/2') | ||
expect(res.status).toBe(404) | ||
expect(await res.text()).toContain('custom 404 page') | ||
}) | ||
} | ||
|
||
describe('Custom 404 Page for static site generation with dynamic routes', () => { | ||
describe('server mode', () => { | ||
afterAll(() => killApp(app)) | ||
|
||
it('should build successfully', async () => { | ||
const { code } = await nextBuild(appDir, [], { | ||
stderr: true, | ||
stdout: true, | ||
}) | ||
|
||
expect(code).toBe(0) | ||
|
||
appPort = await findPort() | ||
|
||
app = await nextStart(appDir, appPort) | ||
}) | ||
|
||
runTests('server') | ||
}) | ||
|
||
describe('serverless mode', () => { | ||
afterAll(async () => { | ||
await fs.remove(nextConfig) | ||
await killApp(app) | ||
}) | ||
|
||
it('should build successfully', async () => { | ||
await fs.writeFile( | ||
nextConfig, | ||
` | ||
module.exports = { target: 'experimental-serverless-trace' } | ||
` | ||
) | ||
const { code } = await nextBuild(appDir, [], { | ||
stderr: true, | ||
stdout: true, | ||
}) | ||
|
||
expect(code).toBe(0) | ||
|
||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
|
||
runTests('serverless') | ||
}) | ||
|
||
describe('dev mode', () => { | ||
beforeAll(async () => { | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests('dev') | ||
}) | ||
}) |