Unverified Commit 5b7b91f3 authored by Jimmy Lai's avatar Jimmy Lai Committed by GitHub

router: add layout and other file supports to parallel routes (#51413)

This PR fixes a bug in which the layout files were not picked up if they were direct children of a parallel route slot.

Note: there's a bunch of other files that I've used for debugging that are not used for the test but I'm leaving them for future me.




link NEXT-969
parent bd466842
......@@ -304,19 +304,26 @@ async function createTreeCodeFromPath(
continue
}
const subSegmentPath = [...segments]
if (parallelKey !== 'children') {
subSegmentPath.push(parallelKey)
}
const normalizedParallelSegments = Array.isArray(parallelSegment)
? parallelSegment.slice(0, 1)
: [parallelSegment]
subSegmentPath.push(
...normalizedParallelSegments.filter(
(segment) => segment !== PAGE_SEGMENT
)
)
const { treeCode: subtreeCode } = await createSubtreePropsFromSegmentPath(
[
...segments,
...(parallelKey === 'children' ? [] : [parallelKey]),
Array.isArray(parallelSegment) ? parallelSegment[0] : parallelSegment,
]
subSegmentPath
)
const parallelSegmentPath =
segmentPath +
'/' +
(parallelKey === 'children' ? '' : `${parallelKey}/`) +
(Array.isArray(parallelSegment) ? parallelSegment[0] : parallelSegment)
const parallelSegmentPath = subSegmentPath.join('/')
// `page` is not included here as it's added above.
const filePaths = await Promise.all(
......@@ -394,7 +401,6 @@ async function createTreeCodeFromPath(
]`
}
}
return {
treeCode: `{
${Object.entries(props)
......@@ -473,10 +479,9 @@ const nextAppLoader: AppLoader = async function nextAppLoader() {
const isParallelRoute = rest[0].startsWith('@')
if (isParallelRoute && rest.length === 2 && rest[1] === 'page') {
matched[rest[0]] = PAGE_SEGMENT
matched[rest[0]] = [PAGE_SEGMENT]
continue
}
if (isParallelRoute) {
matched[rest[0]] = rest.slice(1)
continue
......@@ -485,7 +490,6 @@ const nextAppLoader: AppLoader = async function nextAppLoader() {
matched.children = rest[0]
}
}
return Object.entries(matched)
}
......
export default function Page() {
return 'intercepted parallel layout slug'
}
export default function Layout({ children }: { children: React.ReactNode }) {
return (
<>
<h1> intercepted layout</h1>
{children}
</>
)
}
export default function Layout({ children }) {
return (
<div>
<h1>Parallel group slot Layout</h1>
{children}
</div>
)
}
export default function Layout({ children }) {
return (
<div>
<h1 id="parallel-layout">parallel layout</h1>
{children}
</div>
)
}
import Link from 'next/link'
export default function Layout({ children, slot, groupslot }) {
return (
<div>
<h1>Main Layout</h1>
{children}
<div id="slot">{slot}</div>
<div id="groupslot">{groupslot}</div>
<Link href="/parallel-layout/sub/route">/sub/route</Link>
</div>
)
}
export default function Page() {
return 'parallel layout slug'
}
......@@ -242,6 +242,14 @@ createNextDescribe(
)
})
it('should support layout files in parallel routes', async () => {
const browser = await next.browser('/parallel-layout')
await check(
() => browser.waitForElementByCss('#parallel-layout').text(),
'parallel layout'
)
})
it('should only scroll to the parallel route that was navigated to', async () => {
const browser = await next.browser('/parallel-scroll')
......
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