diff --git a/packages/next/src/server/app-render/app-render.tsx b/packages/next/src/server/app-render/app-render.tsx
index 622f8c6cdd..cd514d34b0 100644
--- a/packages/next/src/server/app-render/app-render.tsx
+++ b/packages/next/src/server/app-render/app-render.tsx
@@ -298,6 +298,17 @@ function makeGetDynamicParamFromSegment(
}
}
+function NonIndex({ ctx }: { ctx: AppRenderContext }) {
+ const is404Page = ctx.pagePath === '/404'
+ const isInvalidStatusCode =
+ typeof ctx.res.statusCode === 'number' && ctx.res.statusCode > 400
+
+ if (is404Page || isInvalidStatusCode) {
+ return
+ }
+ return null
+}
+
// Handle Flight render request. This is only used when client-side navigating. E.g. when you `router.push('/dashboard')` or `router.reload()`.
async function generateFlight(
ctx: AppRenderContext,
@@ -344,8 +355,11 @@ async function generateFlight(
isFirst: true,
// For flight, render metadata inside leaf page
rscPayloadHead: (
- // Adding requestId as react key to make metadata remount for each render
-
+ <>
+
+ {/* Adding requestId as react key to make metadata remount for each render */}
+
+ >
),
injectedCSS: new Set(),
injectedJS: new Set(),
@@ -493,10 +507,7 @@ async function ReactServerApp({ tree, ctx, asNotFound }: ReactServerAppProps) {
couldBeIntercepted={couldBeIntercepted}
initialHead={
<>
- {typeof ctx.res.statusCode === 'number' &&
- ctx.res.statusCode > 400 && (
-
- )}
+
{/* Adding requestId as react key to make metadata remount for each render */}
>
@@ -532,7 +543,6 @@ async function ReactServerError({
},
requestStore: { url },
requestId,
- res,
} = ctx
const [MetadataTree] = createMetadataComponents({
@@ -547,11 +557,9 @@ async function ReactServerError({
const head = (
<>
+
{/* Adding requestId as react key to make metadata remount for each render */}
- {typeof res.statusCode === 'number' && res.statusCode >= 400 && (
-
- )}
{process.env.NODE_ENV === 'development' && (
)}
@@ -1269,7 +1277,7 @@ async function renderToHTMLOrFlightImpl(
setHeader('Location', redirectUrl)
}
- const is404 = res.statusCode === 404
+ const is404 = ctx.res.statusCode === 404
if (!is404 && !hasRedirectError && !shouldBailoutToCSR) {
res.statusCode = 500
}
diff --git a/test/deploy-tests-manifest.json b/test/deploy-tests-manifest.json
index 83464f7180..2e109bb77b 100644
--- a/test/deploy-tests-manifest.json
+++ b/test/deploy-tests-manifest.json
@@ -13,11 +13,6 @@
"app dir - metadata react cache should have same title and page value when navigating"
]
},
- "test/e2e/app-dir/metadata-navigation/metadata-navigation.test.ts": {
- "failed": [
- "app dir - metadata navigation navigation should render root not-found with default metadata"
- ]
- },
"test/e2e/middleware-rewrites/test/index.test.ts": {
"failed": ["Middleware Rewrite should handle catch-all rewrite correctly"]
}
diff --git a/test/e2e/app-dir/not-found/default/app/foo/page.js b/test/e2e/app-dir/not-found/default/app/foo/page.js
new file mode 100644
index 0000000000..9c373d74ea
--- /dev/null
+++ b/test/e2e/app-dir/not-found/default/app/foo/page.js
@@ -0,0 +1,3 @@
+export default function Page() {
+ return
Foo
+}
diff --git a/test/e2e/app-dir/not-found/default/app/layout.js b/test/e2e/app-dir/not-found/default/app/layout.js
new file mode 100644
index 0000000000..750eb927b1
--- /dev/null
+++ b/test/e2e/app-dir/not-found/default/app/layout.js
@@ -0,0 +1,7 @@
+export default function Layout({ children }) {
+ return (
+
+ {children}
+
+ )
+}
diff --git a/test/e2e/app-dir/not-found/default/default.test.ts b/test/e2e/app-dir/not-found/default/default.test.ts
new file mode 100644
index 0000000000..b7e936d5a9
--- /dev/null
+++ b/test/e2e/app-dir/not-found/default/default.test.ts
@@ -0,0 +1,27 @@
+import { nextTestSetup } from 'e2e-utils'
+
+const isPPREnabled = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
+
+describe('app dir - not-found - default', () => {
+ const { next, isNextStart } = nextTestSetup({
+ files: __dirname,
+ skipDeployment: true,
+ })
+
+ it('should has noindex in the head html', async () => {
+ const $ = await next.render$('/does-not-exist')
+ expect(await $('meta[name="robots"]').attr('content')).toBe('noindex')
+ })
+
+ if (isNextStart) {
+ it('should contain noindex contain in the page', async () => {
+ const html = await next.readFile('.next/server/app/_not-found.html')
+ const rsc = await next.readFile(
+ `.next/server/app/_not-found.${isPPREnabled ? 'prefetch.' : ''}rsc`
+ )
+
+ expect(html).toContain('noindex')
+ expect(rsc).toContain('noindex')
+ })
+ }
+})