Unverified Commit f0a6bb42 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

[metadata] skip head cache in default slot (#78206)

parent ee579bf1
import type { FlightRouterState } from '../../../../server/app-render/types'
import type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime'
import { DEFAULT_SEGMENT_KEY } from '../../../../shared/lib/segment'
import { createRouterCacheKey } from '../create-router-cache-key'
export function findHeadInCache(
......@@ -33,6 +34,11 @@ function findHeadInCacheImpl(
for (const key of parallelRoutesKeys) {
const [segment, childParallelRoutes] = parallelRoutes[key]
// If the parallel is not matched and using the default segment,
// skip searching the head from it.
if (segment === DEFAULT_SEGMENT_KEY) {
continue
}
const childSegmentMap = cache.parallelRoutes.get(key)
if (!childSegmentMap) {
continue
......
......@@ -14,6 +14,11 @@ export default function Root({ children }: { children: ReactNode }) {
{`to /parallel-routes-default`}
</Link>
<br />
<Link href="/parallel-routes-no-children" id="to-no-children">
{`to /parallel-routes-no-children`}
</Link>
<br />
</div>
{children}
</body>
......
export default function Page() {
return <p id="bar-page">test-page @bar - 1</p>
}
export const metadata = {
title: 'first page - @bar',
}
export default function Layout({ children }) {
return (
<div>
<h2>@bar Layout</h2>
<div id="bar-children">{children}</div>
</div>
)
}
export default function Page() {
return <p id="bar-page">test-page @bar - 2</p>
}
export const metadata = {
title: 'second page - @bar',
}
export default function Layout({ children }) {
return (
<div>
<h2>@foo Layout</h2>
<div id="foo-children">{children}</div>
</div>
)
}
import { connection } from 'next/server'
import Link from 'next/link'
// skip rendering children
export default function Layout({ bar, foo }) {
return (
<div>
<h1>Parallel Routes Layout - No Children</h1>
<Link href="/parallel-routes-no-children/first" id="to-no-children-first">
{`to /parallel-routes-no-children/first`}
</Link>
<br />
<Link
href="/parallel-routes-no-children/second"
id="to-no-children-second"
>
{`to /parallel-routes-no-children/second`}
</Link>
<br />
<div id="foo-slot">{foo}</div>
<div id="bar-slot">{bar}</div>
</div>
)
}
export async function generateMetadata() {
await connection()
await new Promise((resolve) => setTimeout(resolve, 300))
return {
title: 'parallel-routes-default layout title',
}
}
......@@ -57,4 +57,29 @@ describe('app-dir - metadata-streaming', () => {
expect($('title').length).toBe(1)
expect($('body title').text()).toBe('parallel-routes-default layout title')
})
it('should change metadata when navigating between two pages under a slot when children is not rendered', async () => {
// first page is /parallel-routes-no-children/first,
// second page is /parallel-routes-no-children/second
// navigating between them should change the title metadata
const browser = await next.browser('/parallel-routes-no-children/first')
await retry(async () => {
expect(await browser.elementByCss('title').text()).toBe(
'first page - @bar'
)
})
// go to second page
await browser
.elementByCss('[href="/parallel-routes-no-children/second"]')
.click()
// wait for navigation to finish
await retry(async () => {
expect(await browser.elementByCss('#bar-page').text()).toBe(
'test-page @bar - 2'
)
})
expect(await browser.elementByCss('title').text()).toBe(
'second page - @bar'
)
})
})
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