Commit 3f62f5bc authored by Jimmy Lai's avatar Jimmy Lai

test: add conflicting metadata test and explanatory comments

parent aa5e44d4
......@@ -788,7 +788,11 @@ async function resolveMetadataItemsImpl(
.join('/'),
})
// Process children first, then other parallel routes, for consistent ordering
// Process children first so named parallel route slots are pushed to
// metadataItems last. Since accumulateMetadata applies last-write-wins,
// named slots take precedence over children when both define metadata.
// This ensures deterministic behavior across webpack and Turbopack,
// which may construct loader trees with different key orderings.
const metadataParallelRouteKeys = Object.keys(parallelRoutes)
metadataParallelRouteKeys.sort((a, b) => {
if (a === 'children') return -1
......@@ -918,7 +922,11 @@ async function resolveViewportItemsImpl(
.join('/'),
})
// Process children first, then other parallel routes, for consistent ordering
// Process children first so named parallel route slots are pushed to
// viewportItems last. Since accumulateViewport applies last-write-wins,
// named slots take precedence over children when both define viewport.
// This ensures deterministic behavior across webpack and Turbopack,
// which may construct loader trees with different key orderings.
const viewportParallelRouteKeys = Object.keys(parallelRoutes)
viewportParallelRouteKeys.sort((a, b) => {
if (a === 'children') return -1
......
export default function Page() {
return <div id="bar-conflict-page">bar slot page</div>
}
export const metadata = {
title: 'bar slot title',
}
export default function Page() {
return <div id="foo-conflict-page">foo slot page</div>
}
export default function Page() {
return <div id="children-page">children page</div>
}
export const metadata = {
title: 'children title',
}
......@@ -59,6 +59,15 @@ describe('app-dir - metadata-streaming', () => {
expect($('body title').text()).toBe('parallel-routes-default layout title')
})
it('should use named slot metadata over children when both define conflicting metadata', async () => {
const $ = await next.render$('/parallel-routes/metadata-conflict')
expect($('title').text()).toBe('bar slot title')
const browser = await next.browser('/parallel-routes/metadata-conflict')
expect(await browser.elementByCss('title').text()).toBe('bar slot title')
expect((await browser.elementsByCss('title')).length).toBe(1)
})
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
......
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