Skip to content

Commit 03440f5

Browse files
authored
fix(next): properly 404s not found documents (#7833)
1 parent 0fa6611 commit 03440f5

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

packages/next/src/views/Document/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ export const Document: React.FC<AdminViewProps> = async ({
7575
req,
7676
})
7777

78+
if (!data) {
79+
notFound()
80+
}
81+
7882
const { docPermissions, hasPublishPermission, hasSavePermission } = await getDocumentPermissions({
7983
id,
8084
collectionConfig,

test/admin/e2e/1/e2e.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,20 @@ describe('admin1', () => {
336336
})
337337

338338
describe('routing', () => {
339+
test('should 404 not found root pages', async () => {
340+
await page.goto(`${serverURL}/admin/1234`)
341+
const response = await page.waitForResponse((response) => response.status() === 404)
342+
expect(response).toBeTruthy()
343+
await expect(page.locator('.not-found')).toContainText('Nothing found')
344+
})
345+
346+
test('should 404 not found documents', async () => {
347+
await page.goto(`${postsUrl.collection(postsCollectionSlug)}/1234`)
348+
const response = await page.waitForResponse((response) => response.status() === 404)
349+
expect(response).toBeTruthy()
350+
await expect(page.locator('.not-found')).toContainText('Nothing found')
351+
})
352+
339353
test('should use custom logout route', async () => {
340354
await page.goto(`${serverURL}${adminRoutes.routes.admin}${adminRoutes.admin.routes.logout}`)
341355

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
],
3838
"paths": {
3939
"@payload-config": [
40-
"./test/_community/config.ts"
40+
"./test/admin/config.ts"
4141
],
4242
"@payloadcms/live-preview": [
4343
"./packages/live-preview/src"

0 commit comments

Comments
 (0)