Skip to content

Commit 4fde19a

Browse files
committed
[dev-tools] Initial support for viewing static params of current route from generateStaticParams
1 parent 0d2c1df commit 4fde19a

File tree

11 files changed

+67
-4
lines changed

11 files changed

+67
-4
lines changed

packages/next/src/client/components/react-dev-overlay/app/hot-reloader-client.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,12 @@ export default function HotReload({
613613
appIsrManifestRef,
614614
])
615615

616+
// Using __NEXT_DEVTOOLS_CLIENT_STATE as we already have it.
617+
window.__NEXT_DEVTOOLS_CLIENT_STATE = {
618+
...window.__NEXT_DEVTOOLS_CLIENT_STATE,
619+
staticPathsInfo: state.devToolsClientState.staticPathsInfo,
620+
}
621+
616622
return (
617623
<AppDevOverlay state={state} globalError={globalError}>
618624
{children}

packages/next/src/client/components/react-dev-overlay/shared.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type DevToolsClientState = {
2323
showIndicator: boolean
2424
disableDevIndicator: boolean
2525
}
26+
staticPathsInfo: DevToolsServerState['staticPathsInfo']
2627
}
2728

2829
export interface OverlayState {
@@ -137,14 +138,20 @@ export const INITIAL_OVERLAY_STATE: Omit<OverlayState, 'routerType'> = {
137138
devToolsClientState: {
138139
versionInfo: { installed: '0.0.0', staleness: 'unknown' },
139140
debugInfo: { devtoolsFrontendUrl: undefined },
141+
staticPathsInfo: {
142+
page: '',
143+
pathname: '',
144+
staticPaths: [],
145+
isPageIncludedInStaticPaths: false,
146+
},
140147
devIndicator: {
141148
staticIndicator: false,
142149
disableDevIndicator: false,
143150
/*
144-
This is set to `true` when we can reliably know
145-
whether the indicator is in disabled state or not.
146-
Otherwise the surface would flicker because the disabled flag loads from the config.
147-
*/
151+
This is set to `true` when we can reliably know
152+
whether the indicator is in disabled state or not.
153+
Otherwise the surface would flicker because the disabled flag loads from the config.
154+
*/
148155
showIndicator: false,
149156
},
150157
},

packages/next/src/client/components/react-dev-overlay/ui/components/errors/dev-tools-indicator/dev-tools-indicator.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ const state: OverlayState = {
5959
showIndicator: true,
6060
disableDevIndicator: false,
6161
},
62+
staticPathsInfo: {
63+
page: '',
64+
pathname: '',
65+
staticPaths: [],
66+
isPageIncludedInStaticPaths: false,
67+
},
6268
},
6369
}
6470

packages/next/src/client/components/react-dev-overlay/ui/components/overview/segment-explorer.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ function PageSegmentTreeLayerPresentation({
7979
const nodeName = node.value?.type
8080
const pagePathPrefix = segments.slice(0, -1).join('/')
8181

82+
const staticPathsInfo = window.__NEXT_DEVTOOLS_CLIENT_STATE?.staticPathsInfo
83+
const staticPaths =
84+
staticPathsInfo && staticPathsInfo.pathname === `/${pagePathPrefix}`
85+
? staticPathsInfo.staticPaths
86+
: []
87+
8288
return (
8389
<div className="segment-explorer-item">
8490
{!fileName || level === 0 ? null : (
@@ -95,6 +101,11 @@ function PageSegmentTreeLayerPresentation({
95101
</span>
96102
{pagePathPrefix === '' ? '' : `${pagePathPrefix}/`}
97103
<span className="segment-explorer-filename-path">{fileName}</span>
104+
<div>
105+
{staticPaths.map((path) => (
106+
<div key={path}>{path}</div>
107+
))}
108+
</div>
98109
</div>
99110
</div>
100111
</div>

packages/next/src/client/components/react-dev-overlay/ui/dev-overlay.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ const state: OverlayState = {
3333
showIndicator: true,
3434
disableDevIndicator: false,
3535
},
36+
staticPathsInfo: {
37+
page: '',
38+
pathname: '',
39+
staticPaths: [],
40+
isPageIncludedInStaticPaths: false,
41+
},
3642
},
3743
errors: [
3844
{

packages/next/src/server/base-server.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ import { InvariantError } from '../shared/lib/invariant-error'
177177
import { decodeQueryPathParameter } from './lib/decode-query-path-parameter'
178178
import { getCacheHandlers } from './use-cache/handlers'
179179
import { fixMojibake } from './lib/fix-mojibake'
180+
import { devToolsServerState } from './dev/dev-tools-server-state'
180181

181182
export type FindComponentsResult = {
182183
components: LoadComponentsReturnType
@@ -3060,6 +3061,15 @@ export default abstract class Server<
30603061
const isPageIncludedInStaticPaths =
30613062
staticPathKey && staticPaths?.includes(staticPathKey)
30623063

3064+
if (isPageIncludedInStaticPaths) {
3065+
devToolsServerState.staticPathsInfo = {
3066+
page: components.page,
3067+
pathname,
3068+
staticPaths: staticPaths ?? [],
3069+
isPageIncludedInStaticPaths: !!isPageIncludedInStaticPaths,
3070+
}
3071+
}
3072+
30633073
// When experimental compile is used, no pages have been prerendered,
30643074
// so they should all be blocking.
30653075

packages/next/src/server/dev/dev-tools-server-state.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ export type DevToolsServerState = {
55
devIndicator: { disabledUntil: number }
66
versionInfo: VersionInfo
77
debugInfo: DebugInfo
8+
staticPathsInfo: {
9+
page: string
10+
pathname: string
11+
staticPaths: string[]
12+
isPageIncludedInStaticPaths: boolean
13+
}
814
}
915

1016
export const devToolsServerState: DevToolsServerState = {
@@ -16,4 +22,10 @@ export const devToolsServerState: DevToolsServerState = {
1622
debugInfo: {
1723
devtoolsFrontendUrl: undefined,
1824
},
25+
staticPathsInfo: {
26+
page: '',
27+
pathname: '',
28+
staticPaths: [],
29+
isPageIncludedInStaticPaths: false,
30+
},
1931
}

packages/next/src/server/dev/hot-middleware.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ export class WebpackHotMiddleware {
221221
devtoolsFrontendUrl: this.devtoolsFrontendUrl,
222222
},
223223
devIndicator: devToolsServerState.devIndicator,
224+
staticPathsInfo: devToolsServerState.staticPathsInfo,
224225
},
225226
})
226227
}

packages/next/src/server/dev/hot-reloader-turbopack.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ export async function createHotReloaderTurbopack(
857857
debugInfo: {
858858
devtoolsFrontendUrl,
859859
},
860+
staticPathsInfo: devToolsServerState.staticPathsInfo,
860861
},
861862
}
862863

packages/next/src/server/dev/hot-reloader-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export interface SyncAction {
6060
debugInfo: DebugInfo
6161
versionInfo: VersionInfo
6262
devIndicator: DevToolsServerState['devIndicator']
63+
staticPathsInfo: DevToolsServerState['staticPathsInfo']
6364
}
6465
}
6566
interface BuiltAction {

packages/next/src/shared/lib/devtool/app-segment-tree.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client'
22

33
import { type ReactNode, useEffect, useSyncExternalStore } from 'react'
4+
import type { OverlayState } from '../../../client/components/react-dev-overlay/shared'
45
import { createTrie, type Trie } from './trie'
56

67
export type SegmentNode = {
@@ -10,6 +11,7 @@ export type SegmentNode = {
1011

1112
type DevtoolClientState = {
1213
tree?: Trie<SegmentNode>
14+
staticPathsInfo?: OverlayState['devToolsClientState']['staticPathsInfo']
1315
}
1416

1517
const DEFAULT_CLIENT_STATE =

0 commit comments

Comments
 (0)