Skip to content

Commit

Permalink
override 404 path for nodejs
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Apr 4, 2024
1 parent 427f339 commit c28a5e9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
9 changes: 4 additions & 5 deletions packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1747,11 +1747,10 @@ export default abstract class Server<ServerOptions extends Options = Options> {
{ req, res, pathname, renderOpts: opts }: RequestContext,
{ components, query }: FindComponentsResult
): Promise<ResponsePayload | null> {
const is404Page =
// For edge runtime 404 page, /_not-found needs to be treated as 404 page
(process.env.NEXT_RUNTIME === 'edge' &&
pathname === UNDERSCORE_NOT_FOUND_ROUTE) ||
pathname === '/404'
if (pathname === UNDERSCORE_NOT_FOUND_ROUTE) {
pathname = '/404'
}
const is404Page = pathname === '/404'

// Strip the internal headers.
this.stripInternalHeaders(req)
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/app-dir/not-found-default/app/layout.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import React, { useState } from 'react'
import { useState, Suspense } from 'react'
import { notFound } from 'next/navigation'
import NotFoundTrigger from './not-found-trigger'

Expand All @@ -13,9 +13,9 @@ export default function Root({ children }) {
return (
<html className="root-layout-html">
<body>
<React.Suspense fallback={<div>Loading...</div>}>
<Suspense fallback={<div>Loading...</div>}>
<NotFoundTrigger />
</React.Suspense>
</Suspense>
<button id="trigger-not-found" onClick={() => setClicked(true)}>
Click to not found
</button>
Expand Down
3 changes: 2 additions & 1 deletion test/turbopack-build-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2052,7 +2052,8 @@
"app dir - not-found - basic with default runtime should use the not-found page for non-matching routes",
"app dir - not-found - basic with runtime = edge should escalate notFound to parent layout if no not-found boundary present in current layer",
"app dir - not-found - basic with runtime = edge should match dynamic route not-found boundary correctly",
"app dir - not-found - basic with runtime = edge should use the not-found page for non-matching routes"
"app dir - not-found - basic with runtime = edge should use the not-found page for non-matching routes",
"app dir - not-found - basic should return 404 status code for custom not-found page"
],
"failed": [
"app dir - not-found - basic should include not found client reference manifest in the file trace"
Expand Down

0 comments on commit c28a5e9

Please sign in to comment.