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({ ...@@ -78,7 +78,7 @@ export function createMetadataComponents({
ViewportTree: React.ComponentType ViewportTree: React.ComponentType
getMetadataReady: () => Promise<void> getMetadataReady: () => Promise<void>
getViewportReady: () => Promise<void> getViewportReady: () => Promise<void>
StreamingMetadataOutlet: React.ComponentType StreamingMetadataOutlet: React.ComponentType | null
} { } {
const searchParams = createServerSearchParamsForMetadata( const searchParams = createServerSearchParamsForMetadata(
parsedQuery, parsedQuery,
...@@ -243,13 +243,14 @@ export function createMetadataComponents({ ...@@ -243,13 +243,14 @@ export function createMetadataComponents({
return undefined return undefined
} }
function StreamingMetadataOutlet() { function StreamingMetadataOutletImpl() {
if (serveStreamingMetadata) { return <AsyncMetadataOutlet promise={resolveFinalMetadata()} />
return <AsyncMetadataOutlet promise={resolveFinalMetadata()} />
}
return null
} }
const StreamingMetadataOutlet = serveStreamingMetadata
? StreamingMetadataOutletImpl
: null
return { return {
ViewportTree, ViewportTree,
MetadataTree, MetadataTree,
......
...@@ -42,7 +42,7 @@ export function createComponentTree(props: { ...@@ -42,7 +42,7 @@ export function createComponentTree(props: {
missingSlots?: Set<string> missingSlots?: Set<string>
preloadCallbacks: PreloadCallbacks preloadCallbacks: PreloadCallbacks
authInterrupts: boolean authInterrupts: boolean
StreamingMetadataOutlet: React.ComponentType StreamingMetadataOutlet: React.ComponentType | null
}): Promise<CacheNodeSeedData> { }): Promise<CacheNodeSeedData> {
return getTracer().trace( return getTracer().trace(
NextNodeServerSpan.createComponentTree, NextNodeServerSpan.createComponentTree,
...@@ -395,7 +395,9 @@ async function createComponentTreeInternal({ ...@@ -395,7 +395,9 @@ async function createComponentTreeInternal({
// Use the same condition to render metadataOutlet as metadata // Use the same condition to render metadataOutlet as metadata
const metadataOutlet = StreamingMetadataOutlet ? ( const metadataOutlet = StreamingMetadataOutlet ? (
<StreamingMetadataOutlet /> <StreamingMetadataOutlet />
) : undefined ) : (
<MetadataOutlet ready={getMetadataReady} />
)
const notFoundElement = NotFound ? ( const notFoundElement = NotFound ? (
<> <>
...@@ -716,9 +718,6 @@ async function createComponentTreeInternal({ ...@@ -716,9 +718,6 @@ async function createComponentTreeInternal({
{layerAssets} {layerAssets}
<OutletBoundary> <OutletBoundary>
<MetadataOutlet ready={getViewportReady} /> <MetadataOutlet ready={getViewportReady} />
{/* Blocking metadata outlet */}
<MetadataOutlet ready={getMetadataReady} />
{/* Streaming metadata outlet */}
{metadataOutlet} {metadataOutlet}
</OutletBoundary> </OutletBoundary>
</React.Fragment>, </React.Fragment>,
......
...@@ -56,7 +56,7 @@ export async function walkTreeWithFlightRouterState({ ...@@ -56,7 +56,7 @@ export async function walkTreeWithFlightRouterState({
getViewportReady: () => Promise<void> getViewportReady: () => Promise<void>
ctx: AppRenderContext ctx: AppRenderContext
preloadCallbacks: PreloadCallbacks preloadCallbacks: PreloadCallbacks
StreamingMetadataOutlet: React.ComponentType StreamingMetadataOutlet: React.ComponentType | null
}): Promise<FlightDataPath[]> { }): Promise<FlightDataPath[]> {
const { const {
renderOpts: { nextFontManifest, experimental }, renderOpts: { nextFontManifest, experimental },
......
...@@ -9,13 +9,12 @@ describe('app-dir - metadata-streaming', () => { ...@@ -9,13 +9,12 @@ describe('app-dir - metadata-streaming', () => {
it('should only insert metadata once for parallel routes when slots match', async () => { it('should only insert metadata once for parallel routes when slots match', async () => {
const browser = await next.browser('/parallel-routes') const browser = await next.browser('/parallel-routes')
expect((await browser.elementsByCss('head title')).length).toBe(1) expect((await browser.elementsByCss('title')).length).toBe(1)
expect((await browser.elementsByCss('body title')).length).toBe(0)
expect(await browser.elementByCss('title').text()).toBe('parallel title') expect(await browser.elementByCss('title').text()).toBe('parallel title')
const $ = await next.render$('/parallel-routes') const $ = await next.render$('/parallel-routes')
expect($('title').length).toBe(1) expect($('title').length).toBe(1)
// We can't ensure if it's inserted into head or body since it's a race condition, // We can't ensure if it's inserted into head or body since it's a race condition,
// where sometimes the metadata can be suspended. // where sometimes the metadata can be suspended.
expect($('title').text()).toBe('parallel title') expect($('title').text()).toBe('parallel title')
...@@ -51,7 +50,7 @@ describe('app-dir - metadata-streaming', () => { ...@@ -51,7 +50,7 @@ describe('app-dir - metadata-streaming', () => {
const browser = await next.browser('/parallel-routes-default') const browser = await next.browser('/parallel-routes-default')
expect((await browser.elementsByCss('title')).length).toBe(1) 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' '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