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