Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit747d365

Browse files
authored
Fix metadata prop merging (#69807)
### WhatFixes metadata merging issue on 14.2. There's a bug with React on 14.2 as it bit outdated: while generating rsc payload, if we use fragment to wrap the metadata and noindex component, it will miss all the data. It works well with separating them as an array.It also requires#64058 to be applied as well so the output not-found page will having correct status 404, and then we can generate noindex metatag based on correct statusFixes#69778
1 parent196dab6 commit747d365

File tree

10 files changed

+120
-8
lines changed

10 files changed

+120
-8
lines changed

‎packages/next/src/server/app-render/app-render.tsx‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,11 @@ async function generateFlight(
319319
flightRouterState,
320320
isFirst:true,
321321
// For flight, render metadata inside leaf page
322-
rscPayloadHead:(
323-
<>
324-
<NonIndexctx={ctx}/>
325-
{/* Adding requestId as react key to make metadata remount for each render */}
326-
<MetadataTreekey={requestId}/>
327-
</>
328-
),
322+
// NOTE: in 14.2, fragment doesn't work well with React, using array instead
323+
rscPayloadHead:[
324+
<MetadataTreekey={requestId}/>,
325+
<NonIndexkey="noindex"ctx={ctx}/>,
326+
],
329327
injectedCSS:newSet(),
330328
injectedJS:newSet(),
331329
injectedFontPreloadTags:newSet(),
@@ -531,12 +529,12 @@ async function ReactServerError({
531529

532530
consthead=(
533531
<>
534-
<NonIndexctx={ctx}/>
535532
{/* Adding requestId as react key to make metadata remount for each render */}
536533
<MetadataTreekey={requestId}/>
537534
{process.env.NODE_ENV==='development'&&(
538535
<metaname="next-error"content="not-found"/>
539536
)}
537+
<NonIndexctx={ctx}/>
540538
</>
541539
)
542540

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import{Metadata}from'next'
2+
3+
exportconstmetadata:Metadata={
4+
title:'Product Layout',
5+
}
6+
7+
exportdefaultfunctionLayout({
8+
children,
9+
}:Readonly<{
10+
children:React.ReactNode
11+
}>){
12+
return<>{children}</>
13+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exportdefaultfunctionPage(){
2+
return<div>Product page content</div>
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
typeLayoutProps={
2+
children:React.ReactNode
3+
}
4+
5+
exportdefaultfunctionLayout({ children}:LayoutProps){
6+
return<div>{children}</div>
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
importLinkfrom'next/link'
2+
3+
exportdefaultfunctionPage(){
4+
return(
5+
<div>
6+
<div>Home header</div>
7+
<Linkhref="/product"id="product-link">
8+
Product
9+
</Link>
10+
</div>
11+
)
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
typeLayoutProps={
2+
children:React.ReactNode
3+
}
4+
5+
exportdefaultfunctionLayout({ children}:LayoutProps){
6+
return<>{children}</>
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
importLinkfrom'next/link'
2+
3+
exportdefaultfunctionPage(){
4+
return(
5+
<div>
6+
<h1id="product-title">Product header</h1>
7+
<Linkhref="/"id="home-link">
8+
Go to Home page
9+
</Link>
10+
</div>
11+
)
12+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
importtype{Metadata}from'next'
2+
3+
exportconstmetadata:Metadata={
4+
title:'Home Layout',
5+
description:'Generated by create next app',
6+
}
7+
8+
exportdefaultfunctionRootLayout({
9+
header,
10+
children,
11+
}:Readonly<{
12+
header:React.ReactNode
13+
children:React.ReactNode
14+
}>){
15+
return(
16+
<htmllang="en">
17+
<bodyclassName={`antialiased bg-gray-50 text-black`}>
18+
{header}
19+
{children}
20+
</body>
21+
</html>
22+
)
23+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
exportdefaultfunctionHome(){
2+
return(
3+
<div>
4+
<h3id="home-title">Home page content</h3>
5+
</div>
6+
)
7+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import{createNextDescribe}from'e2e-utils'
2+
3+
createNextDescribe(
4+
'app-dir - metadata-navigation',
5+
{
6+
files:__dirname,
7+
},
8+
({ next})=>{
9+
it('should show the index title',async()=>{
10+
constbrowser=awaitnext.browser('/')
11+
expect(awaitbrowser.elementByCss('title').text()).toBe('Home Layout')
12+
})
13+
14+
it('should show target page metadata after navigation',async()=>{
15+
constbrowser=awaitnext.browser('/')
16+
awaitbrowser.elementByCss('#product-link').click()
17+
awaitbrowser.waitForElementByCss('#product-title')
18+
expect(awaitbrowser.elementByCss('title').text()).toBe('Product Layout')
19+
})
20+
21+
it('should show target page metadata after navigation with back',async()=>{
22+
constbrowser=awaitnext.browser('/')
23+
awaitbrowser.elementByCss('#product-link').click()
24+
awaitbrowser.waitForElementByCss('#product-title')
25+
awaitbrowser.elementByCss('#home-link').click()
26+
awaitbrowser.waitForElementByCss('#home-title')
27+
expect(awaitbrowser.elementByCss('title').text()).toBe('Home Layout')
28+
})
29+
}
30+
)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp