File tree Expand file tree Collapse file tree 10 files changed +120
-8
lines changed
packages/next/src/server/app-render
test/e2e/app-dir/metadata-navigation Expand file tree Collapse file tree 10 files changed +120
-8
lines changed Original file line number Diff line number Diff 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- < NonIndex ctx = { ctx } />
325- { /* Adding requestId as react key to make metadata remount for each render */ }
326- < MetadataTree key = { requestId } />
327- </ >
328- ) ,
322+ // NOTE: in 14.2, fragment doesn't work well with React, using array instead
323+ rscPayloadHead : [
324+ < MetadataTree key = { requestId } /> ,
325+ < NonIndex key = "noindex" ctx = { ctx } /> ,
326+ ] ,
329327 injectedCSS : new Set ( ) ,
330328 injectedJS : new Set ( ) ,
331329 injectedFontPreloadTags : new Set ( ) ,
@@ -531,12 +529,12 @@ async function ReactServerError({
531529
532530 const head = (
533531 < >
534- < NonIndex ctx = { ctx } />
535532 { /* Adding requestId as react key to make metadata remount for each render */ }
536533 < MetadataTree key = { requestId } />
537534 { process . env . NODE_ENV === 'development' && (
538535 < meta name = "next-error" content = "not-found" />
539536 ) }
537+ < NonIndex ctx = { ctx } />
540538 </ >
541539 )
542540
Original file line number Diff line number Diff line change 1+ import { Metadata } from 'next'
2+
3+ export const metadata : Metadata = {
4+ title : 'Product Layout' ,
5+ }
6+
7+ export default function Layout ( {
8+ children,
9+ } : Readonly < {
10+ children : React . ReactNode
11+ } > ) {
12+ return < > { children } </ >
13+ }
Original file line number Diff line number Diff line change 1+ export default function Page ( ) {
2+ return < div > Product page content</ div >
3+ }
Original file line number Diff line number Diff line change 1+ type LayoutProps = {
2+ children : React . ReactNode
3+ }
4+
5+ export default function Layout ( { children } : LayoutProps ) {
6+ return < div > { children } </ div >
7+ }
Original file line number Diff line number Diff line change 1+ import Link from 'next/link'
2+
3+ export default function Page ( ) {
4+ return (
5+ < div >
6+ < div > Home header</ div >
7+ < Link href = "/product" id = "product-link" >
8+ Product
9+ </ Link >
10+ </ div >
11+ )
12+ }
Original file line number Diff line number Diff line change 1+ type LayoutProps = {
2+ children : React . ReactNode
3+ }
4+
5+ export default function Layout ( { children } : LayoutProps ) {
6+ return < > { children } </ >
7+ }
Original file line number Diff line number Diff line change 1+ import Link from 'next/link'
2+
3+ export default function Page ( ) {
4+ return (
5+ < div >
6+ < h1 id = "product-title" > Product header</ h1 >
7+ < Link href = "/" id = "home-link" >
8+ Go to Home page
9+ </ Link >
10+ </ div >
11+ )
12+ }
Original file line number Diff line number Diff line change 1+ import type { Metadata } from 'next'
2+
3+ export const metadata : Metadata = {
4+ title : 'Home Layout' ,
5+ description : 'Generated by create next app' ,
6+ }
7+
8+ export default function RootLayout ( {
9+ header,
10+ children,
11+ } : Readonly < {
12+ header : React . ReactNode
13+ children : React . ReactNode
14+ } > ) {
15+ return (
16+ < html lang = "en" >
17+ < body className = { `antialiased bg-gray-50 text-black` } >
18+ { header }
19+ { children }
20+ </ body >
21+ </ html >
22+ )
23+ }
Original file line number Diff line number Diff line change 1+ export default function Home ( ) {
2+ return (
3+ < div >
4+ < h3 id = "home-title" > Home page content</ h3 >
5+ </ div >
6+ )
7+ }
Original file line number Diff line number Diff line change 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+ const browser = await next . browser ( '/' )
11+ expect ( await browser . elementByCss ( 'title' ) . text ( ) ) . toBe ( 'Home Layout' )
12+ } )
13+
14+ it ( 'should show target page metadata after navigation' , async ( ) => {
15+ const browser = await next . browser ( '/' )
16+ await browser . elementByCss ( '#product-link' ) . click ( )
17+ await browser . waitForElementByCss ( '#product-title' )
18+ expect ( await browser . elementByCss ( 'title' ) . text ( ) ) . toBe ( 'Product Layout' )
19+ } )
20+
21+ it ( 'should show target page metadata after navigation with back' , async ( ) => {
22+ const browser = await next . browser ( '/' )
23+ await browser . elementByCss ( '#product-link' ) . click ( )
24+ await browser . waitForElementByCss ( '#product-title' )
25+ await browser . elementByCss ( '#home-link' ) . click ( )
26+ await browser . waitForElementByCss ( '#home-title' )
27+ expect ( await browser . elementByCss ( 'title' ) . text ( ) ) . toBe ( 'Home Layout' )
28+ } )
29+ }
30+ )
You can’t perform that action at this time.
0 commit comments