Skip to content

Commit

Permalink
[streaming metadata]: ensure metadata boundary is only rendered once …
Browse files Browse the repository at this point in the history
…on client nav
  • Loading branch information
ztanner committed Mar 1, 2025
1 parent 6f6001a commit ba18daf
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ async function generateDynamicRSCPayload(
<NonIndex ctx={ctx} />
{/* Adding requestId as react key to make metadata remount for each render */}
<ViewportTree key={requestId} />
{StreamingMetadata ? <StreamingMetadata /> : null}
<StaticMetadata />
</React.Fragment>
),
Expand All @@ -532,7 +533,6 @@ async function generateDynamicRSCPayload(
getViewportReady,
getMetadataReady,
preloadCallbacks,
StreamingMetadata,
StreamingMetadataOutlet,
})
).map((path) => path.slice(1)) // remove the '' (root) segment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export async function walkTreeWithFlightRouterState({
getMetadataReady,
ctx,
preloadCallbacks,
StreamingMetadata,
StreamingMetadataOutlet,
}: {
loaderTreeToFilter: LoaderTree
Expand All @@ -56,7 +55,6 @@ export async function walkTreeWithFlightRouterState({
getViewportReady: () => Promise<void>
ctx: AppRenderContext
preloadCallbacks: PreloadCallbacks
StreamingMetadata: React.ComponentType<{}> | null
StreamingMetadataOutlet: React.ComponentType<{}>
}): Promise<FlightDataPath[]> {
const {
Expand Down Expand Up @@ -206,7 +204,7 @@ export async function walkTreeWithFlightRouterState({
getMetadataReady,
preloadCallbacks,
authInterrupts: experimental.authInterrupts,
StreamingMetadata,
StreamingMetadata: null,
StreamingMetadataOutlet,
}
)
Expand Down Expand Up @@ -267,7 +265,6 @@ export async function walkTreeWithFlightRouterState({
getViewportReady,
getMetadataReady,
preloadCallbacks,
StreamingMetadata,
StreamingMetadataOutlet,
})

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return 'test-page @bar'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return 'test-page @foo'
}
11 changes: 10 additions & 1 deletion test/e2e/app-dir/metadata-streaming/app/parallel-routes/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import Link from 'next/link'

export default function Page() {
return <div>Hello from Nested</div>
return (
<div>
Hello from Nested{' '}
<Link href="/parallel-routes/test-page">
To /parallel-routes/test-page
</Link>
</div>
)
}

export const metadata = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { connection } from 'next/server'

export default function TestPage() {
return 'test page'
}

export async function generateMetadata() {
await connection()
await new Promise((resolve) => setTimeout(resolve, 3000))
return {
title: `Dynamic api ${Math.random()}`,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ describe('app-dir - metadata-streaming', () => {

const $ = await next.render$('/parallel-routes')
expect($('title').length).toBe(1)

// validate behavior remains the same on client navigations
await browser.elementByCss('[href="/parallel-routes/test-page"]').click()

expect((await browser.elementsByCss('title')).length).toBe(1)
})

describe('dynamic api', () => {
Expand Down

0 comments on commit ba18daf

Please sign in to comment.