Skip to content

Commit a3a0984

Browse files
committed
[segment explorer] capture defined boundaries
1 parent 81f0c76 commit a3a0984

File tree

4 files changed

+65
-9
lines changed

4 files changed

+65
-9
lines changed

packages/next/src/client/components/layout-router.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,16 @@ export default function OuterLayoutRouter({
665665
.SegmentStateProvider as typeof import('../../next-devtools/userspace/app/segment-explorer-node').SegmentStateProvider as typeof import('../../next-devtools/userspace/app/segment-explorer-node').SegmentStateProvider
666666

667667
child = (
668-
<SegmentStateProvider key={stateKey}>{child}</SegmentStateProvider>
668+
<SegmentStateProvider
669+
key={stateKey}
670+
boundaries={{
671+
notFound: !!notFound,
672+
loading: !!loadingModuleData,
673+
error: !!error,
674+
}}
675+
>
676+
{child}
677+
</SegmentStateProvider>
669678
)
670679
}
671680

packages/next/src/next-devtools/dev-overlay/components/overview/segment-boundary-trigger.tsx

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { Menu } from '@base-ui-components/react/menu'
33
import type { SegmentNodeState } from '../../../userspace/app/segment-explorer-node'
44

55
export function SegmentBoundaryTrigger({
6+
boundaries,
67
onSelectBoundary,
78
offset,
89
}: {
10+
boundaries: SegmentNodeState['boundaries']
911
onSelectBoundary: SegmentNodeState['setBoundaryType']
1012
offset: number
1113
}) {
@@ -16,10 +18,26 @@ export function SegmentBoundaryTrigger({
1618
})
1719
const shadowRootRef = useRef<ShadowRoot>(shadowRoot)
1820

21+
console.log('boundaries', boundaries)
1922
const triggerOptions = [
20-
{ label: 'Trigger Loading', value: 'loading', icon: <LoadingIcon /> },
21-
{ label: 'Trigger Error', value: 'error', icon: <ErrorIcon /> },
22-
{ label: 'Trigger Not Found', value: 'not-found', icon: <NotFoundIcon /> },
23+
{
24+
label: 'Loading',
25+
value: 'loading',
26+
icon: <LoadingIcon />,
27+
disabled: !boundaries.loading,
28+
},
29+
{
30+
label: 'Error',
31+
value: 'error',
32+
icon: <ErrorIcon />,
33+
disabled: !boundaries.error,
34+
},
35+
{
36+
label: 'Not Found',
37+
value: 'not-found',
38+
icon: <NotFoundIcon />,
39+
disabled: !boundaries.notFound,
40+
},
2341
]
2442

2543
const resetOption = {
@@ -74,6 +92,7 @@ export function SegmentBoundaryTrigger({
7492
key={option.value}
7593
className="segment-boundary-dropdown-item"
7694
onClick={() => handleSelect(option.value)}
95+
disabled={option.disabled}
7796
>
7897
{option.icon}
7998
{option.label}
@@ -86,6 +105,14 @@ export function SegmentBoundaryTrigger({
86105
key={resetOption.value}
87106
className="segment-boundary-dropdown-item"
88107
onClick={() => handleSelect(resetOption.value)}
108+
// disable reset if there is no boundary
109+
disabled={
110+
!(
111+
boundaries.loading ||
112+
boundaries.error ||
113+
boundaries.notFound
114+
)
115+
}
89116
>
90117
{resetOption.icon}
91118
{resetOption.label}
@@ -274,9 +301,14 @@ export const styles = `
274301
width: 100%;
275302
}
276303
304+
.segment-boundary-dropdown-item[data-disabled] {
305+
color: var(--color-gray-400);
306+
cursor: not-allowed;
307+
}
308+
277309
.segment-boundary-dropdown-item svg {
278310
margin-right: 12px;
279-
color: var(--color-gray-900);
311+
color: currentColor;
280312
}
281313
282314
.segment-boundary-dropdown-item:hover {

packages/next/src/next-devtools/dev-overlay/components/overview/segment-explorer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ function PageSegmentTreeLayerPresentation({
208208
<SegmentBoundaryTrigger
209209
offset={6}
210210
onSelectBoundary={pageChild.value.setBoundaryType}
211+
boundaries={pageChild.value.boundaries}
211212
/>
212213
)}
213214
</div>

packages/next/src/next-devtools/userspace/app/segment-explorer-node.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const SEGMENT_EXPLORER_SIMULATED_ERROR_MESSAGE =
1919
export type SegmentNodeState = {
2020
type: string
2121
pagePath: string
22+
boundaries: { notFound: boolean; loading: boolean; error: boolean }
2223
boundaryType: string | null
2324
setBoundaryType: (type: 'error' | 'not-found' | 'loading' | null) => void
2425
}
@@ -30,15 +31,16 @@ function SegmentTrieNode({
3031
type: string
3132
pagePath: string
3233
}): React.ReactNode {
33-
const { boundaryType, setBoundaryType } = useSegmentState()
34+
const { boundaryType, setBoundaryType, boundaries } = useSegmentState()
3435
const nodeState: SegmentNodeState = useMemo(
3536
() => ({
3637
type,
3738
pagePath,
39+
boundaries,
3840
boundaryType,
3941
setBoundaryType,
4042
}),
41-
[type, pagePath, boundaryType, setBoundaryType]
43+
[type, pagePath, boundaryType, setBoundaryType, boundaries]
4244
)
4345

4446
// Use `useLayoutEffect` to ensure the state is updated during suspense.
@@ -112,14 +114,22 @@ export function SegmentViewNode({
112114
}
113115

114116
const SegmentStateContext = createContext<{
117+
boundaries: { notFound: boolean; loading: boolean; error: boolean }
115118
boundaryType: 'not-found' | 'error' | 'loading' | null
116119
setBoundaryType: (type: 'not-found' | 'error' | 'loading' | null) => void
117120
}>({
121+
boundaries: { notFound: false, loading: false, error: false },
118122
boundaryType: null,
119123
setBoundaryType: () => {},
120124
})
121125

122-
export function SegmentStateProvider({ children }: { children: ReactNode }) {
126+
export function SegmentStateProvider({
127+
children,
128+
boundaries,
129+
}: {
130+
children: ReactNode
131+
boundaries: { notFound: boolean; loading: boolean; error: boolean }
132+
}) {
123133
const [boundaryType, setBoundaryType] = useState<
124134
'not-found' | 'error' | 'loading' | null
125135
>(null)
@@ -143,7 +153,11 @@ export function SegmentStateProvider({ children }: { children: ReactNode }) {
143153
return (
144154
<SegmentStateContext.Provider
145155
key={errorBoundaryKey}
146-
value={{ boundaryType, setBoundaryType: setBoundaryTypeAndReload }}
156+
value={{
157+
boundaryType,
158+
setBoundaryType: setBoundaryTypeAndReload,
159+
boundaries,
160+
}}
147161
>
148162
{children}
149163
</SegmentStateContext.Provider>

0 commit comments

Comments
 (0)