Skip to content

[dev-tools] Initial support for viewing static params of current route from generateStaticParams #79510

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

Draft
wants to merge 4 commits into
base: jiwon/05-23-_dev_tools_refactor_calculate_dev_indicator_state_from_the_server
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type DevToolsClientState = DevToolsServerState & {
staticIndicator: boolean
isReady: boolean
}
staticPathsInfo: DevToolsServerState['staticPathsInfo']
}

export interface OverlayState {
Expand Down Expand Up @@ -129,6 +130,12 @@ export const INITIAL_OVERLAY_STATE: Omit<OverlayState, 'routerType'> = {
devToolsClientState: {
versionInfo: { installed: '0.0.0', staleness: 'unknown' },
debugInfo: { devtoolsFrontendUrl: undefined },
staticPathsInfo: {
page: '',
pathname: '',
staticPaths: [],
isPageIncludedInStaticPaths: false,
},
devIndicator: {
staticIndicator: false,
isDisabled: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ const state: OverlayState = {
isDisabled: false,
disabledUntil: 0,
},
staticPathsInfo: {
page: '',
pathname: '',
staticPaths: [],
isPageIncludedInStaticPaths: false,
},
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export function DevToolsIndicator({
const [isDevToolsIndicatorVisible, setIsDevToolsIndicatorVisible] =
useState(true)

// Using __NEXT_DEVTOOLS_CLIENT_STATE to avoid prop drilling.
window.__NEXT_DEVTOOLS_CLIENT_STATE = {
...window.__NEXT_DEVTOOLS_CLIENT_STATE,
staticPathsInfo: state.devToolsClientState.staticPathsInfo,
}

return (
<DevToolsPopover
routerType={state.routerType}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ function PageSegmentTreeLayerPresentation({
const nodeName = node.value?.type
const pagePathPrefix = segments.slice(0, -1).join('/')

const staticPathsInfo = window.__NEXT_DEVTOOLS_CLIENT_STATE?.staticPathsInfo
const staticPaths =
staticPathsInfo &&
nodeName === 'page' &&
staticPathsInfo.pathname === `/${pagePathPrefix}`
? staticPathsInfo.staticPaths
: []

return (
<div className="segment-explorer-item">
{!fileName || level === 0 ? null : (
Expand All @@ -95,6 +103,11 @@ function PageSegmentTreeLayerPresentation({
</span>
{pagePathPrefix === '' ? '' : `${pagePathPrefix}/`}
<span className="segment-explorer-filename-path">{fileName}</span>
<div>
{staticPaths.map((path) => (
<div key={path}>{path}</div>
))}
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -160,6 +173,28 @@ export const DEV_TOOLS_INFO_RENDER_FILES_STYLES = css`
overflow-y: auto;
padding: 0 12px;
font-size: var(--size-14);
max-height: 500px;

&::-webkit-scrollbar {
width: 6px;
height: 6px;
border-radius: 0 0 1rem 1rem;
margin-bottom: 1rem;
}

&::-webkit-scrollbar-button {
display: none;
}

&::-webkit-scrollbar-track {
border-radius: 0 0 1rem 1rem;
background-color: var(--color-background-100);
}

&::-webkit-scrollbar-thumb {
border-radius: 1rem;
background-color: var(--color-gray-500);
}
}

.segment-explorer-item-row {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ const state: OverlayState = {
isDisabled: false,
disabledUntil: 0,
},
staticPathsInfo: {
page: '',
pathname: '',
staticPaths: [],
isPageIncludedInStaticPaths: false,
},
},
errors: [
{
Expand Down
10 changes: 10 additions & 0 deletions packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ import { InvariantError } from '../shared/lib/invariant-error'
import { decodeQueryPathParameter } from './lib/decode-query-path-parameter'
import { getCacheHandlers } from './use-cache/handlers'
import { fixMojibake } from './lib/fix-mojibake'
import { devToolsServerState } from './dev/dev-tools-server-state'

export type FindComponentsResult = {
components: LoadComponentsReturnType
Expand Down Expand Up @@ -3060,6 +3061,15 @@ export default abstract class Server<
const isPageIncludedInStaticPaths =
staticPathKey && staticPaths?.includes(staticPathKey)

if (isPageIncludedInStaticPaths) {
devToolsServerState.staticPathsInfo = {
page: components.page,
pathname,
staticPaths: staticPaths ?? [],
isPageIncludedInStaticPaths: !!isPageIncludedInStaticPaths,
}
}

// When experimental compile is used, no pages have been prerendered,
// so they should all be blocking.

Expand Down
12 changes: 12 additions & 0 deletions packages/next/src/server/dev/dev-tools-server-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export type DevToolsServerState = {
}
versionInfo: VersionInfo
debugInfo: DebugInfo
staticPathsInfo: {
page: string
pathname: string
staticPaths: string[]
isPageIncludedInStaticPaths: boolean
}
}

export const devToolsServerState: DevToolsServerState = {
Expand All @@ -22,4 +28,10 @@ export const devToolsServerState: DevToolsServerState = {
debugInfo: {
devtoolsFrontendUrl: undefined,
},
staticPathsInfo: {
page: '',
pathname: '',
staticPaths: [],
isPageIncludedInStaticPaths: false,
},
}
1 change: 1 addition & 0 deletions packages/next/src/server/dev/hot-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export class WebpackHotMiddleware {
devtoolsFrontendUrl: this.devtoolsFrontendUrl,
},
devIndicator: devToolsServerState.devIndicator,
staticPathsInfo: devToolsServerState.staticPathsInfo,
},
})
}
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/server/dev/hot-reloader-turbopack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ export async function createHotReloaderTurbopack(
debugInfo: {
devtoolsFrontendUrl,
},
staticPathsInfo: devToolsServerState.staticPathsInfo,
},
}

Expand Down
1 change: 1 addition & 0 deletions packages/next/src/server/dev/hot-reloader-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface SyncAction {
debugInfo: DebugInfo
versionInfo: VersionInfo
devIndicator: DevToolsServerState['devIndicator']
staticPathsInfo: DevToolsServerState['staticPathsInfo']
}
}
interface BuiltAction {
Expand Down
2 changes: 2 additions & 0 deletions packages/next/src/shared/lib/devtool/app-segment-tree.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client'

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

export type SegmentNode = {
Expand All @@ -10,6 +11,7 @@ export type SegmentNode = {

type DevtoolClientState = {
tree?: Trie<SegmentNode>
staticPathsInfo?: OverlayState['devToolsClientState']['staticPathsInfo']
}

const DEFAULT_CLIENT_STATE =
Expand Down
Loading