Skip to content

Commit 51ffc25

Browse files
authored
[metadata] remove the duplicate metadata in the error boundary (#76791)
### What Those metadata were added into error boundaries but they're actually duplicated, we already have the actual metadata in the page and the metadata outlet can trigger the error boundary. The metadata element in the error boundary is not necessary.
1 parent 3355371 commit 51ffc25

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

packages/next/src/server/app-render/create-component-tree.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -411,23 +411,20 @@ async function createComponentTreeInternal({
411411
const notFoundElement = NotFound ? (
412412
<>
413413
<NotFound />
414-
{metadata}
415414
{notFoundStyles}
416415
</>
417416
) : undefined
418417

419418
const forbiddenElement = Forbidden ? (
420419
<>
421420
<Forbidden />
422-
{metadata}
423421
{forbiddenStyles}
424422
</>
425423
) : undefined
426424

427425
const unauthorizedElement = Unauthorized ? (
428426
<>
429427
<Unauthorized />
430-
{metadata}
431428
{unauthorizedStyles}
432429
</>
433430
) : undefined
@@ -858,7 +855,6 @@ async function createComponentTreeInternal({
858855
{notFoundStyles}
859856
<NotFound />
860857
</SegmentComponent>
861-
{metadata}
862858
</>
863859
) : undefined
864860
}

test/e2e/app-dir/parallel-routes-not-found/app/layout.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ export default function Layout({
66
slot: React.ReactNode
77
}) {
88
return (
9-
<html>
9+
<html lang="en" className="layout">
1010
<body>
1111
{children}
1212
{slot}
1313
</body>
1414
</html>
1515
)
1616
}
17+
18+
export const metadata = {
19+
title: 'layout title',
20+
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/**
22
* @type {import('next').NextConfig}
33
*/
4-
const nextConfig = {
5-
pageExtensions: ['tsx', 'ts'],
6-
}
4+
const nextConfig = {}
75

86
module.exports = nextConfig

test/e2e/app-dir/parallel-routes-not-found/parallel-routes-not-found.test.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { nextTestSetup } from 'e2e-utils'
22

3+
const isPPR = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
4+
35
describe('parallel-routes-and-interception', () => {
4-
const { next, skipped } = nextTestSetup({
6+
const { next, isNextDev, skipped } = nextTestSetup({
57
files: __dirname,
68
// TODO: remove after deployment handling is updated
79
skipDeployment: true,
@@ -21,5 +23,28 @@ describe('parallel-routes-and-interception', () => {
2123

2224
// we also check that the #children-slot id is not present
2325
expect(await browser.hasElementByCssSelector('#children-slot')).toBe(false)
26+
27+
if (isPPR && !isNextDev) {
28+
let $ = await next.render$('/')
29+
expect($('title').text()).toBe('')
30+
31+
$ = await next.render$('/', null, {
32+
headers: {
33+
'User-Agent': 'Discordbot',
34+
},
35+
})
36+
expect($('title').text()).toBe('layout title')
37+
} else {
38+
const $ = await next.render$('/')
39+
expect($('title').text()).toBe('layout title')
40+
}
41+
})
42+
43+
it('should render the title once for the non-existed route', async () => {
44+
const browser = await next.browser('/non-existed')
45+
const titles = await browser.elementsByCss('title')
46+
47+
// FIXME: (metadata), the title should only be rendered once and using the not-found title
48+
expect(titles).toHaveLength(3)
2449
})
2550
})

test/e2e/app-dir/parallel-routes-not-found/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
"target": "ES2017"
2222
},
2323
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
24-
"exclude": ["node_modules"]
24+
"exclude": ["node_modules", "**/*.test.ts", "**/*.test.tsx"]
2525
}

0 commit comments

Comments
 (0)