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

[segment explorer] display default page in segment explorer (#80716)

parent 8324d810
......@@ -242,7 +242,8 @@ export const DEV_TOOLS_INFO_RENDER_FILES_STYLES = css`
user-select: none;
}
.segment-explorer-file-label--layout,
.segment-explorer-file-label--template {
.segment-explorer-file-label--template,
.segment-explorer-file-label--default {
background-color: var(--color-gray-300);
color: var(--color-gray-1000);
}
......
......@@ -25,6 +25,7 @@ import type {
UseCacheLayoutComponentProps,
UseCachePageComponentProps,
} from '../use-cache/use-cache-wrapper'
import { DEFAULT_SEGMENT_KEY } from '../../shared/lib/segment'
/**
* Use the provided loader tree to create the React Component tree.
......@@ -431,8 +432,6 @@ async function createComponentTreeInternal({
tree,
})
const nodeName = modType ?? 'page'
// TODO: Combine this `map` traversal with the loop below that turns the array
// into an object.
const parallelRouteMap = await Promise.all(
......@@ -743,10 +742,16 @@ async function createComponentTreeInternal({
}
}
const pageFilePath = getConventionPathByType(tree, dir, 'page')
const isDefaultSegment = segment === DEFAULT_SEGMENT_KEY
const pageFilePath =
getConventionPathByType(tree, dir, 'page') ??
getConventionPathByType(tree, dir, 'defaultPage')
const wrappedPageElement =
isSegmentViewEnabled && pageFilePath ? (
<SegmentViewNode type={nodeName} pagePath={pageFilePath}>
<SegmentViewNode
type={isDefaultSegment ? 'default' : 'page'}
pagePath={pageFilePath}
>
{pageElement}
</SegmentViewNode>
) : (
......@@ -931,7 +936,7 @@ async function createComponentTreeInternal({
const layoutFilePath = getConventionPathByType(tree, dir, 'layout')
const wrappedSegmentNode =
isSegmentViewEnabled && layoutFilePath ? (
<SegmentViewNode type={nodeName} pagePath={layoutFilePath}>
<SegmentViewNode type="layout" pagePath={layoutFilePath}>
{segmentNode}
</SegmentViewNode>
) : (
......@@ -1136,6 +1141,7 @@ function getConventionPathByType(
| 'loading'
| 'forbidden'
| 'unauthorized'
| 'defaultPage'
) {
const modules = tree[2]
const conventionPath = modules[conventionType]
......
......@@ -5,6 +5,8 @@ const hrefs = [
'/blog/~/grid',
'/soft-navigation/a',
'/file-segments',
'/parallel-default',
'/parallel-default/subroute',
]
export default function Page() {
......
export default function Default() {
return '@bar default'
}
export default function Layout({ children }) {
return (
<div>
<h1>@bar Layout</h1>
<div id="bar-children">{children}</div>
</div>
)
}
export default function Page() {
return <div>Bar Slot</div>
}
export default function Page() {
return <div>Subroute</div>
}
export default function Default() {
return '@foo default'
}
export default function Layout({ children }) {
return (
<div>
<h1>@foo Layout</h1>
<div id="foo-children">{children}</div>
</div>
)
}
export default function Page() {
return <div>Foo Slot</div>
}
export default function Page() {
return 'default page'
}
import Link from 'next/link'
export default function Layout({ children, bar, foo }) {
return (
<div>
<h1>Nested Layout</h1>
<div>
<div>
<Link href="/parallel-default/subroute">
<div id="subroute-link">Go to /parallel-default/subroute</div>
</Link>
</div>
<div>
<Link href="/parallel-default">
<div id="grid-link">Go to /parallel-default</div>
</Link>
</div>
</div>
<div id="nested-children">{children}</div>
<div id="foo-slot">{foo}</div>
<div id="bar-slot">{bar}</div>
</div>
)
}
export default function Page() {
return <div>Hello from Nested</div>
}
......@@ -189,4 +189,21 @@ describe('segment-explorer', () => {
error.tsx"
`)
})
it('should display parallel routes default page when present', async () => {
const browser = await next.browser('/parallel-default/subroute')
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/
layout.tsx
parallel-default/
layout.tsx
default.tsx
@bar/
layout.tsx
subroute/
page.tsx
@foo/
default.tsx"
`)
})
})
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