Skip to content

Commit c071f53

Browse files
committed
fix: ignore metadata from default.js
1 parent cde0f93 commit c071f53

File tree

17 files changed

+138
-1
lines changed

17 files changed

+138
-1
lines changed

packages/next/src/lib/metadata/resolve-metadata.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import {
5151
import { resolveIcons } from './resolvers/resolve-icons'
5252
import { getTracer } from '../../server/lib/trace/tracer'
5353
import { ResolveMetadataSpan } from '../../server/lib/trace/constants'
54-
import { PAGE_SEGMENT_KEY } from '../../shared/lib/segment'
54+
import { DEFAULT_SEGMENT_KEY, PAGE_SEGMENT_KEY } from '../../shared/lib/segment'
5555
import * as Log from '../../build/output/log'
5656
import type { WorkStore } from '../../server/app-render/work-async-storage.external'
5757
import type {
@@ -443,6 +443,10 @@ async function collectMetadata({
443443
const hasErrorConventionComponent = Boolean(
444444
errorConvention && tree[2][errorConvention]
445445
)
446+
// If it's default.js, ignore the metadata
447+
if (tree[0] === DEFAULT_SEGMENT_KEY) {
448+
return
449+
}
446450
if (errorConvention) {
447451
mod = await getComponentTypeModule(tree, 'layout')
448452
modType = errorConvention
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Link from 'next/link'
2+
import React from 'react'
3+
4+
export default function Root({ children }: { children: React.ReactNode }) {
5+
return (
6+
<html>
7+
<body>
8+
<div>
9+
<Link href="/nested">to nested</Link>
10+
</div>
11+
<div>
12+
<Link href="/nested/subroute">to nested subroute</Link>
13+
</div>
14+
<h1>Root Layout</h1>
15+
<div>{children}</div>
16+
</body>
17+
</html>
18+
)
19+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Default() {
2+
return '@bar default'
3+
}
4+
5+
export const metadata = {
6+
title: '@bar - page',
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function Layout({ children }) {
2+
return (
3+
<div>
4+
<h1>@bar Layout</h1>
5+
<div id="bar-children">{children}</div>
6+
</div>
7+
)
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Page() {
2+
return <div>Bar Slot</div>
3+
}
4+
5+
export const metadata = {
6+
title: '@bar - page',
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Page() {
2+
return <div>Subroute</div>
3+
}
4+
5+
export const metadata = {
6+
title: 'subroute - page',
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Default() {
2+
return '@foo default'
3+
}
4+
5+
export const metadata = {
6+
title: '@foo - default',
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function Layout({ children }) {
2+
return (
3+
<div>
4+
<h1>@foo Layout</h1>
5+
<div id="foo-children">{children}</div>
6+
</div>
7+
)
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Page() {
2+
return <div>Foo Slot</div>
3+
}
4+
5+
export const metadata = {
6+
title: '@foo - page',
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Page() {
2+
return 'default page'
3+
}
4+
5+
export const metadata = {
6+
title: 'nested - default',
7+
}

0 commit comments

Comments
 (0)