Skip to content

Commit 686ba5b

Browse files
authored
fix: static not-found missing in prerender manifest (#82199)
1 parent 0b2c3b1 commit 686ba5b

File tree

7 files changed

+39
-9
lines changed

7 files changed

+39
-9
lines changed

packages/next/src/build/index.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ import {
7676
MIDDLEWARE_REACT_LOADABLE_MANIFEST,
7777
SERVER_REFERENCE_MANIFEST,
7878
FUNCTIONS_CONFIG_MANIFEST,
79-
UNDERSCORE_NOT_FOUND_ROUTE_ENTRY,
8079
UNDERSCORE_NOT_FOUND_ROUTE,
80+
UNDERSCORE_NOT_FOUND_ROUTE_ENTRY,
8181
DYNAMIC_CSS_MANIFEST,
8282
TURBOPACK_CLIENT_MIDDLEWARE_MANIFEST,
8383
} from '../shared/lib/constants'
@@ -3090,12 +3090,6 @@ export default async function build(
30903090
]
30913091

30923092
for (const prerenderedRoute of prerenderedRoutes) {
3093-
// TODO: check if still needed?
3094-
// Exclude the /_not-found route.
3095-
if (prerenderedRoute.pathname === UNDERSCORE_NOT_FOUND_ROUTE) {
3096-
continue
3097-
}
3098-
30993093
if (
31003094
isRoutePPREnabled &&
31013095
prerenderedRoute.fallbackRouteParams &&
@@ -3114,7 +3108,6 @@ export default async function build(
31143108
// Handle all the static routes.
31153109
for (const route of staticPrerenderedRoutes) {
31163110
if (isDynamicRoute(page) && route.pathname === page) continue
3117-
if (route.pathname === UNDERSCORE_NOT_FOUND_ROUTE) continue
31183111

31193112
const {
31203113
metadata = {},
@@ -3164,9 +3157,13 @@ export default async function build(
31643157
}
31653158

31663159
const meta = collectMeta(metadata)
3160+
const status =
3161+
route.pathname === UNDERSCORE_NOT_FOUND_ROUTE
3162+
? 404
3163+
: meta.status
31673164

31683165
prerenderManifest.routes[route.pathname] = {
3169-
initialStatus: meta.status,
3166+
initialStatus: status,
31703167
initialHeaders: meta.headers,
31713168
renderingMode: isAppPPREnabled
31723169
? isRoutePPREnabled

packages/next/src/export/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,10 @@ async function exportAppImpl(
763763
if (!options.buildExport && prerenderManifest) {
764764
await Promise.all(
765765
Object.keys(prerenderManifest.routes).map(async (unnormalizedRoute) => {
766+
// Skip handling /_not-found route, it will copy the 404.html file later
767+
if (unnormalizedRoute === '/_not-found') {
768+
return
769+
}
766770
const { srcRoute } = prerenderManifest!.routes[unnormalizedRoute]
767771
const appPageName = mapAppRouteToPage.get(srcRoute || '')
768772
const pageName = appPageName || srcRoute || unnormalizedRoute

test/e2e/app-dir/app-static/app-static.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,31 @@ describe('app-dir static/dynamic handling', () => {
987987
"initialRevalidateSeconds": false,
988988
"srcRoute": "/",
989989
},
990+
"/_not-found": {
991+
"allowHeader": [
992+
"host",
993+
"x-matched-path",
994+
"x-prerender-revalidate",
995+
"x-prerender-revalidate-if-generated",
996+
"x-next-revalidated-tags",
997+
"x-next-revalidate-tag-token",
998+
],
999+
"dataRoute": "/_not-found.rsc",
1000+
"experimentalBypassFor": [
1001+
{
1002+
"key": "next-action",
1003+
"type": "header",
1004+
},
1005+
{
1006+
"key": "content-type",
1007+
"type": "header",
1008+
"value": "multipart/form-data;.*",
1009+
},
1010+
],
1011+
"initialRevalidateSeconds": false,
1012+
"initialStatus": 404,
1013+
"srcRoute": "/_not-found",
1014+
},
9901015
"/api/large-data": {
9911016
"allowHeader": [
9921017
"host",

test/e2e/app-dir/cache-components-dynamic-imports/cache-components-dynamic-imports.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ describe('async imports in cacheComponents', () => {
3939

4040
expect(prerenderedRoutes).toMatchInlineSnapshot(`
4141
[
42+
"/_not-found",
4243
"/inside-render/client/async-module",
4344
"/inside-render/client/sync-module",
4445
"/inside-render/route-handler/async-module",

test/e2e/app-dir/metadata-static-generation/metadata-static-generation.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const isPPREnabled = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
2424
const staticRoutes = prerenderManifest.routes
2525
expect(Object.keys(staticRoutes).sort()).toEqual([
2626
'/',
27+
'/_not-found',
2728
'/suspenseful/static',
2829
])
2930
})

test/e2e/app-dir/metadata-streaming-static-generation/metadata-streaming-static-generation.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const isPPREnabled = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
2222
const staticRoutes = prerenderManifest.routes
2323
expect(Object.keys(staticRoutes).sort()).toEqual([
2424
'/',
25+
'/_not-found',
2526
'/slow/static',
2627
'/suspenseful/static',
2728
])

test/e2e/app-dir/use-cache/use-cache.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ describe('use-cache', () => {
473473

474474
expect(prerenderedRouteKeys).toEqual(
475475
[
476+
'/_not-found',
476477
// [id] route, first entry in generateStaticParams
477478
expect.stringMatching(/\/a\d/),
478479
withCacheComponents && '/api',

0 commit comments

Comments
 (0)