Unverified Commit 686ba5bd authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

fix: static not-found missing in prerender manifest (#82199)

parent 0b2c3b15
......@@ -76,8 +76,8 @@ import {
MIDDLEWARE_REACT_LOADABLE_MANIFEST,
SERVER_REFERENCE_MANIFEST,
FUNCTIONS_CONFIG_MANIFEST,
UNDERSCORE_NOT_FOUND_ROUTE_ENTRY,
UNDERSCORE_NOT_FOUND_ROUTE,
UNDERSCORE_NOT_FOUND_ROUTE_ENTRY,
DYNAMIC_CSS_MANIFEST,
TURBOPACK_CLIENT_MIDDLEWARE_MANIFEST,
} from '../shared/lib/constants'
......@@ -3090,12 +3090,6 @@ export default async function build(
]
for (const prerenderedRoute of prerenderedRoutes) {
// TODO: check if still needed?
// Exclude the /_not-found route.
if (prerenderedRoute.pathname === UNDERSCORE_NOT_FOUND_ROUTE) {
continue
}
if (
isRoutePPREnabled &&
prerenderedRoute.fallbackRouteParams &&
......@@ -3114,7 +3108,6 @@ export default async function build(
// Handle all the static routes.
for (const route of staticPrerenderedRoutes) {
if (isDynamicRoute(page) && route.pathname === page) continue
if (route.pathname === UNDERSCORE_NOT_FOUND_ROUTE) continue
const {
metadata = {},
......@@ -3164,9 +3157,13 @@ export default async function build(
}
const meta = collectMeta(metadata)
const status =
route.pathname === UNDERSCORE_NOT_FOUND_ROUTE
? 404
: meta.status
prerenderManifest.routes[route.pathname] = {
initialStatus: meta.status,
initialStatus: status,
initialHeaders: meta.headers,
renderingMode: isAppPPREnabled
? isRoutePPREnabled
......
......@@ -763,6 +763,10 @@ async function exportAppImpl(
if (!options.buildExport && prerenderManifest) {
await Promise.all(
Object.keys(prerenderManifest.routes).map(async (unnormalizedRoute) => {
// Skip handling /_not-found route, it will copy the 404.html file later
if (unnormalizedRoute === '/_not-found') {
return
}
const { srcRoute } = prerenderManifest!.routes[unnormalizedRoute]
const appPageName = mapAppRouteToPage.get(srcRoute || '')
const pageName = appPageName || srcRoute || unnormalizedRoute
......
......@@ -987,6 +987,31 @@ describe('app-dir static/dynamic handling', () => {
"initialRevalidateSeconds": false,
"srcRoute": "/",
},
"/_not-found": {
"allowHeader": [
"host",
"x-matched-path",
"x-prerender-revalidate",
"x-prerender-revalidate-if-generated",
"x-next-revalidated-tags",
"x-next-revalidate-tag-token",
],
"dataRoute": "/_not-found.rsc",
"experimentalBypassFor": [
{
"key": "next-action",
"type": "header",
},
{
"key": "content-type",
"type": "header",
"value": "multipart/form-data;.*",
},
],
"initialRevalidateSeconds": false,
"initialStatus": 404,
"srcRoute": "/_not-found",
},
"/api/large-data": {
"allowHeader": [
"host",
......
......@@ -39,6 +39,7 @@ describe('async imports in cacheComponents', () => {
expect(prerenderedRoutes).toMatchInlineSnapshot(`
[
"/_not-found",
"/inside-render/client/async-module",
"/inside-render/client/sync-module",
"/inside-render/route-handler/async-module",
......
......@@ -24,6 +24,7 @@ const isPPREnabled = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
const staticRoutes = prerenderManifest.routes
expect(Object.keys(staticRoutes).sort()).toEqual([
'/',
'/_not-found',
'/suspenseful/static',
])
})
......
......@@ -22,6 +22,7 @@ const isPPREnabled = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
const staticRoutes = prerenderManifest.routes
expect(Object.keys(staticRoutes).sort()).toEqual([
'/',
'/_not-found',
'/slow/static',
'/suspenseful/static',
])
......
......@@ -473,6 +473,7 @@ describe('use-cache', () => {
expect(prerenderedRouteKeys).toEqual(
[
'/_not-found',
// [id] route, first entry in generateStaticParams
expect.stringMatching(/\/a\d/),
withCacheComponents && '/api',
......
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