Unverified Commit 13b8d58a authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

[metadata] only render one metadata outlet (#80146)

parent 895908a3
......@@ -78,7 +78,7 @@ export function createMetadataComponents({
ViewportTree: React.ComponentType
getMetadataReady: () => Promise<void>
getViewportReady: () => Promise<void>
StreamingMetadataOutlet: React.ComponentType
StreamingMetadataOutlet: React.ComponentType | null
} {
const searchParams = createServerSearchParamsForMetadata(
parsedQuery,
......@@ -243,12 +243,13 @@ export function createMetadataComponents({
return undefined
}
function StreamingMetadataOutlet() {
if (serveStreamingMetadata) {
function StreamingMetadataOutletImpl() {
return <AsyncMetadataOutlet promise={resolveFinalMetadata()} />
}
return null
}
const StreamingMetadataOutlet = serveStreamingMetadata
? StreamingMetadataOutletImpl
: null
return {
ViewportTree,
......
......@@ -42,7 +42,7 @@ export function createComponentTree(props: {
missingSlots?: Set<string>
preloadCallbacks: PreloadCallbacks
authInterrupts: boolean
StreamingMetadataOutlet: React.ComponentType
StreamingMetadataOutlet: React.ComponentType | null
}): Promise<CacheNodeSeedData> {
return getTracer().trace(
NextNodeServerSpan.createComponentTree,
......@@ -395,7 +395,9 @@ async function createComponentTreeInternal({
// Use the same condition to render metadataOutlet as metadata
const metadataOutlet = StreamingMetadataOutlet ? (
<StreamingMetadataOutlet />
) : undefined
) : (
<MetadataOutlet ready={getMetadataReady} />
)
const notFoundElement = NotFound ? (
<>
......@@ -716,9 +718,6 @@ async function createComponentTreeInternal({
{layerAssets}
<OutletBoundary>
<MetadataOutlet ready={getViewportReady} />
{/* Blocking metadata outlet */}
<MetadataOutlet ready={getMetadataReady} />
{/* Streaming metadata outlet */}
{metadataOutlet}
</OutletBoundary>
</React.Fragment>,
......
......@@ -56,7 +56,7 @@ export async function walkTreeWithFlightRouterState({
getViewportReady: () => Promise<void>
ctx: AppRenderContext
preloadCallbacks: PreloadCallbacks
StreamingMetadataOutlet: React.ComponentType
StreamingMetadataOutlet: React.ComponentType | null
}): Promise<FlightDataPath[]> {
const {
renderOpts: { nextFontManifest, experimental },
......
......@@ -9,8 +9,7 @@ describe('app-dir - metadata-streaming', () => {
it('should only insert metadata once for parallel routes when slots match', async () => {
const browser = await next.browser('/parallel-routes')
expect((await browser.elementsByCss('head title')).length).toBe(1)
expect((await browser.elementsByCss('body title')).length).toBe(0)
expect((await browser.elementsByCss('title')).length).toBe(1)
expect(await browser.elementByCss('title').text()).toBe('parallel title')
const $ = await next.render$('/parallel-routes')
......@@ -51,7 +50,7 @@ describe('app-dir - metadata-streaming', () => {
const browser = await next.browser('/parallel-routes-default')
expect((await browser.elementsByCss('title')).length).toBe(1)
expect(await browser.elementByCss('body title').text()).toBe(
expect(await browser.elementByCss('title').text()).toBe(
'parallel-routes-default layout title'
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment