Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
356cdf23
Unverified
Commit
356cdf23
authored
Jun 06, 2025
by
Jiachi Liu
Committed by
GitHub
Jun 06, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[devtool] display segment explorer as tree view (#80261)
parent
b8b85c67
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
120 additions
and
42 deletions
+120
-42
segment-explorer.tsx
...t-dev-overlay/ui/components/overview/segment-explorer.tsx
+42
-21
layout.tsx
.../app-dir/segment-explorer/app/(v2)/blog/(team)/layout.tsx
+8
-0
page.tsx
...-explorer/app/(v2)/blog/(team)/~/(overview)/grid/page.tsx
+7
-0
layout.tsx
...ent-explorer/app/(v2)/blog/(team)/~/(overview)/layout.tsx
+8
-0
layout.tsx
.../development/app-dir/segment-explorer/app/(v2)/layout.tsx
+8
-0
segment-explorer.test.ts
...lopment/app-dir/segment-explorer/segment-explorer.test.ts
+47
-21
No files found.
packages/next/src/client/components/react-dev-overlay/ui/components/overview/segment-explorer.tsx
View file @
356cdf23
...
@@ -62,6 +62,7 @@ function PageSegmentTree({ tree }: { tree: Trie<SegmentNode> | undefined }) {
...
@@ -62,6 +62,7 @@ function PageSegmentTree({ tree }: { tree: Trie<SegmentNode> | undefined }) {
tree=
{
tree
}
tree=
{
tree
}
node=
{
tree
.
getRoot
()
}
node=
{
tree
.
getRoot
()
}
level=
{
0
}
level=
{
0
}
segment=
""
/>
/>
</
div
>
</
div
>
)
)
...
@@ -69,10 +70,12 @@ function PageSegmentTree({ tree }: { tree: Trie<SegmentNode> | undefined }) {
...
@@ -69,10 +70,12 @@ function PageSegmentTree({ tree }: { tree: Trie<SegmentNode> | undefined }) {
function
PageSegmentTreeLayerPresentation
({
function
PageSegmentTreeLayerPresentation
({
tree
,
tree
,
segment
,
node
,
node
,
level
,
level
,
}:
{
}:
{
tree
:
Trie
<
SegmentNode
>
tree
:
Trie
<
SegmentNode
>
segment
:
string
node
:
TrieNode
<
SegmentNode
>
node
:
TrieNode
<
SegmentNode
>
level
:
number
level
:
number
})
{
})
{
...
@@ -81,11 +84,9 @@ function PageSegmentTreeLayerPresentation({
...
@@ -81,11 +84,9 @@ function PageSegmentTreeLayerPresentation({
const
segments
=
pagePath
.
split
(
'/'
)
||
[]
const
segments
=
pagePath
.
split
(
'/'
)
||
[]
const
fileName
=
segments
.
pop
()
||
''
const
fileName
=
segments
.
pop
()
||
''
const
segmentPath
=
segments
.
join
(
'/'
)
const
childrenKeys
=
Object
.
keys
(
node
.
children
)
let
pagePathPrefix
=
segmentPath
const
sortedChildrenKeys
=
childrenKeys
.
sort
((
a
,
b
)
=>
{
const
childrenKeys
=
Object
.
keys
(
node
.
children
).
sort
((
a
,
b
)
=>
{
// Prioritize if it's a file convention like layout or page,
// Prioritize if it's a file convention like layout or page,
// then the rest parallel routes.
// then the rest parallel routes.
const
aHasExt
=
a
.
includes
(
'.'
)
const
aHasExt
=
a
.
includes
(
'.'
)
...
@@ -98,13 +99,11 @@ function PageSegmentTreeLayerPresentation({
...
@@ -98,13 +99,11 @@ function PageSegmentTreeLayerPresentation({
return
(
return
(
<
div
<
div
className=
{
cx
(
className=
"segment-explorer-item"
'segment-explorer-item'
,
data
-
nextjs
-
devtool
-
segment
-
explorer
-
segment=
{
segment
}
level
>
1
&&
'segment-explorer-item--nested'
)
}
>
>
{
!
fileName
||
level
===
0
?
null
:
(
{
fileName
?
(
<
div
className=
"segment-explorer-item-row"
>
<
div
className=
{
cx
(
'segment-explorer-item-row'
)
}
>
<
div
className=
"segment-explorer-line"
>
<
div
className=
"segment-explorer-line"
>
<
div
className=
{
`segment-explorer-line-text-${nodeName}`
}
>
<
div
className=
{
`segment-explorer-line-text-${nodeName}`
}
>
<
span
<
span
...
@@ -115,20 +114,39 @@ function PageSegmentTreeLayerPresentation({
...
@@ -115,20 +114,39 @@ function PageSegmentTreeLayerPresentation({
>
>
{
nodeName
===
'layout'
?
ICONS
.
layout
:
ICONS
.
page
}
{
nodeName
===
'layout'
?
ICONS
.
layout
:
ICONS
.
page
}
</
span
>
</
span
>
{
pagePathPrefix
===
''
?
''
:
`${pagePathPrefix}/`
}
<
span
className=
"segment-explorer-filename-path"
>
{
fileName
}
</
span
>
<
span
className=
"segment-explorer-filename-path"
>
{
fileName
}
</
span
>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
)
:
segment
?
(
<
div
className=
{
'segment-explorer-item-row'
}
>
<
div
className=
"segment-explorer-line"
>
<
div
className=
{
`segment-explorer-line-text-${nodeName}`
}
>
<
span
className=
{
cx
(
'segment-explorer-line-icon'
,
`segment-explorer-line-icon-${nodeName}`
)
}
)
}
></
span
>
<
span
className=
"segment-explorer-filename-path"
>
{
`${segment}/`
}
</
span
>
</
div
>
</
div
>
</
div
>
)
:
null
}
<
div
className=
"tree-node-expanded-rendered-children"
>
<
div
{
childrenKeys
.
map
((
segment
)
=>
{
className=
"segment-explorer-segment-children"
const
child
=
node
.
children
[
segment
]
data
-
nextjs
-
devtool
-
segment
-
explorer
-
level=
{
level
}
>
{
sortedChildrenKeys
.
map
((
childSegment
)
=>
{
const
child
=
node
.
children
[
childSegment
]
return
(
return
(
child
&&
(
child
&&
(
<
PageSegmentTreeLayerPresentation
<
PageSegmentTreeLayerPresentation
key=
{
segment
}
key=
{
childSegment
}
segment=
{
childSegment
}
tree=
{
tree
}
tree=
{
tree
}
node=
{
child
}
node=
{
child
}
level=
{
level
+
1
}
level=
{
level
+
1
}
...
@@ -163,10 +181,6 @@ export const DEV_TOOLS_INFO_RENDER_FILES_STYLES = css`
...
@@ -163,10 +181,6 @@ export const DEV_TOOLS_INFO_RENDER_FILES_STYLES = css`
font-size: var(--size-14);
font-size: var(--size-14);
}
}
.segment-explorer-item--nested {
padding-left: 20px;
}
.segment-explorer-item-row {
.segment-explorer-item-row {
display: flex;
display: flex;
align-items: center;
align-items: center;
...
@@ -174,6 +188,13 @@ export const DEV_TOOLS_INFO_RENDER_FILES_STYLES = css`
...
@@ -174,6 +188,13 @@ export const DEV_TOOLS_INFO_RENDER_FILES_STYLES = css`
padding: 2px 0;
padding: 2px 0;
}
}
[data-nextjs-devtool-segment-explorer-level].segment-explorer-segment-children {
padding-left: 20px;
}
[data-nextjs-devtool-segment-explorer-level='0'].segment-explorer-segment-children {
padding-left: 0px;
}
.segment-explorer-filename-path {
.segment-explorer-filename-path {
display: inline-block;
display: inline-block;
}
}
...
...
test/development/app-dir/segment-explorer/app/(v2)/blog/(team)/layout.tsx
0 → 100644
View file @
356cdf23
export
default
function
Layout
({
children
})
{
return
(
<
div
>
<
h3
>
Nested Layout
</
h3
>
<
div
className=
"nested-children"
>
{
children
}
</
div
>
</
div
>
)
}
test/development/app-dir/segment-explorer/app/(v2)/blog/(team)/~/(overview)/grid/page.tsx
0 → 100644
View file @
356cdf23
export
default
function
Page
()
{
return
(
<
div
>
Page
<
br
/>
</
div
>
)
}
test/development/app-dir/segment-explorer/app/(v2)/blog/(team)/~/(overview)/layout.tsx
0 → 100644
View file @
356cdf23
export
default
function
Layout
({
children
})
{
return
(
<
div
>
<
h3
>
Nested Layout
</
h3
>
<
div
className=
"nested-children"
>
{
children
}
</
div
>
</
div
>
)
}
test/development/app-dir/segment-explorer/app/(v2)/layout.tsx
0 → 100644
View file @
356cdf23
export
default
function
Layout
({
children
})
{
return
(
<
div
>
<
h3
>
Nested Layout
</
h3
>
<
div
className=
"nested-children"
>
{
children
}
</
div
>
</
div
>
)
}
test/development/app-dir/segment-explorer/segment-explorer.test.ts
View file @
356cdf23
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
openDevToolsIndicatorPopover
}
from
'next-test-utils'
import
{
openDevToolsIndicatorPopover
}
from
'next-test-utils'
import
{
Playwright
}
from
'next-webdriver'
describe
(
'segment-explorer'
,
()
=>
{
async
function
getSegmentExplorerContent
(
browser
:
Playwright
)
{
const
{
next
}
=
nextTestSetup
({
files
:
__dirname
,
})
it
(
'should render the segment explorer'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/parallel-routes'
)
// open the devtool button
// open the devtool button
await
openDevToolsIndicatorPopover
(
browser
)
await
openDevToolsIndicatorPopover
(
browser
)
...
@@ -21,14 +15,46 @@ describe('segment-explorer', () => {
...
@@ -21,14 +15,46 @@ describe('segment-explorer', () => {
const
content
=
await
browser
.
elementByCss
(
const
content
=
await
browser
.
elementByCss
(
'[data-nextjs-devtool-segment-explorer]'
'[data-nextjs-devtool-segment-explorer]'
)
)
expect
(
await
content
.
text
()).
toMatchInlineSnapshot
(
`
return
content
.
text
()
"app/layout.tsx
}
app/parallel-routes/layout.tsx
app/parallel-routes/page.tsx
describe
(
'segment-explorer'
,
()
=>
{
app/parallel-routes/@bar/layout.tsx
const
{
next
}
=
nextTestSetup
({
app/parallel-routes/@bar/page.tsx
files
:
__dirname
,
app/parallel-routes/@foo/layout.tsx
})
app/parallel-routes/@foo/page.tsx"
it
(
'should render the segment explorer for parallel routes'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/parallel-routes'
)
expect
(
await
getSegmentExplorerContent
(
browser
)).
toMatchInlineSnapshot
(
`
"app/
layout.tsx
parallel-routes/
layout.tsx
page.tsx
@bar/
layout.tsx
page.tsx
@foo/
layout.tsx
page.tsx"
`
)
})
it
(
'should render the segment explorer for nested routes'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/blog/~/grid'
)
expect
(
await
getSegmentExplorerContent
(
browser
)).
toMatchInlineSnapshot
(
`
"app/
layout.tsx
(v2)/
layout.tsx
blog/
(team)/
layout.tsx
~/
(overview)/
layout.tsx
grid/
page.tsx"
`
)
`
)
})
})
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment