Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

router: support layout/special files as direct children of parallel routes #51604

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 15 additions & 5 deletions packages/next/src/build/webpack/loaders/next-app-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const FILE_TYPES = {

const GLOBAL_ERROR_FILE_TYPE = 'global-error'
const PAGE_SEGMENT = 'page$'
const PARALLEL_CHILDREN_SEGMENT = 'children$'

type DirResolver = (pathToResolve: string) => string
type PathResolver = (
Expand Down Expand Up @@ -315,7 +316,8 @@ async function createTreeCodeFromPath(

subSegmentPath.push(
...normalizedParallelSegments.filter(
(segment) => segment !== PAGE_SEGMENT
(segment) =>
segment !== PAGE_SEGMENT && segment !== PARALLEL_CHILDREN_SEGMENT
)
)

Expand Down Expand Up @@ -359,10 +361,17 @@ async function createTreeCodeFromPath(
}
}

let parallelSegmentKey = Array.isArray(parallelSegment)
? parallelSegment[0]
: parallelSegment

parallelSegmentKey =
parallelSegmentKey === PARALLEL_CHILDREN_SEGMENT
? 'children'
: parallelSegmentKey

props[normalizeParallelKey(parallelKey)] = `[
'${
Array.isArray(parallelSegment) ? parallelSegment[0] : parallelSegment
}',
'${parallelSegmentKey}',
${subtreeCode},
{
${definedFilePaths
Expand Down Expand Up @@ -483,7 +492,8 @@ const nextAppLoader: AppLoader = async function nextAppLoader() {
continue
}
if (isParallelRoute) {
matched[rest[0]] = rest.slice(1)
// we insert a special marker in order to also process layout/etc files at the slot level
matched[rest[0]] = [PARALLEL_CHILDREN_SEGMENT, ...rest.slice(1)]
continue
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => null
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import Link from 'next/link'

export default function Page() {
return 'slot children'
return (
<>
<div>slot children</div>
<Link href="/parallel-layout/subroute">parallel subroute</Link>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default ({ children }) => {
return (
<div>
<h1 id="parallel-subroute">parallel subroute layout</h1>
{children}
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return 'subroute children'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => null
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,17 @@ createNextDescribe(
() => browser.waitForElementByCss('#parallel-layout').text(),
'parallel layout'
)

// navigate to /parallel-layout/subroute
await browser.elementByCss('[href="/parallel-layout/subroute"]').click()
await check(
() => browser.waitForElementByCss('#parallel-layout').text(),
'parallel layout'
)
await check(
() => browser.waitForElementByCss('#parallel-subroute').text(),
'parallel subroute layout'
)
})

it('should only scroll to the parallel route that was navigated to', async () => {
Expand Down