Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 &&
Expand All @@ -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 = {},
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/next/src/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions test/e2e/app-dir/app-static/app-static.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
])
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
])
Expand Down
1 change: 1 addition & 0 deletions test/e2e/app-dir/use-cache/use-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ describe('use-cache', () => {

expect(prerenderedRouteKeys).toEqual(
[
'/_not-found',
// [id] route, first entry in generateStaticParams
expect.stringMatching(/\/a\d/),
withCacheComponents && '/api',
Expand Down
Loading