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

[devtool] fix explorer flag consuming and style (#80110)

parent 81ab1ffc
...@@ -369,6 +369,8 @@ export async function handler( ...@@ -369,6 +369,8 @@ export async function handler(
enableTainting: nextConfig.experimental.taint, enableTainting: nextConfig.experimental.taint,
// @ts-expect-error fix issue with readonly regex object type // @ts-expect-error fix issue with readonly regex object type
htmlLimitedBots: nextConfig.htmlLimitedBots, htmlLimitedBots: nextConfig.htmlLimitedBots,
devtoolSegmentExplorer:
nextConfig.experimental.devtoolSegmentExplorer,
reactMaxHeadersLength: nextConfig.reactMaxHeadersLength, reactMaxHeadersLength: nextConfig.reactMaxHeadersLength,
multiZoneDraftMode, multiZoneDraftMode,
......
...@@ -409,7 +409,7 @@ function DevToolsPopover({ ...@@ -409,7 +409,7 @@ function DevToolsPopover({
/> />
{process.env.__NEXT_DEVTOOL_SEGMENT_EXPLORER ? ( {process.env.__NEXT_DEVTOOL_SEGMENT_EXPLORER ? (
<MenuItem <MenuItem
data-rendered-files data-segment-explorer
label="Segment Explorer" label="Segment Explorer"
value={<ChevronRight />} value={<ChevronRight />}
onClick={() => setOpen(OVERLAYS.SegmentExplorer)} onClick={() => setOpen(OVERLAYS.SegmentExplorer)}
......
...@@ -54,7 +54,10 @@ function PageSegmentTree({ tree }: { tree: Trie<SegmentNode> | undefined }) { ...@@ -54,7 +54,10 @@ function PageSegmentTree({ tree }: { tree: Trie<SegmentNode> | undefined }) {
return null return null
} }
return ( return (
<div className="segment-explorer-content"> <div
className="segment-explorer-content"
data-nextjs-devtool-segment-explorer
>
<PageSegmentTreeLayerPresentation <PageSegmentTreeLayerPresentation
tree={tree} tree={tree}
node={tree.getRoot()} node={tree.getRoot()}
...@@ -147,11 +150,6 @@ export const DEV_TOOLS_INFO_RENDER_FILES_STYLES = css` ...@@ -147,11 +150,6 @@ export const DEV_TOOLS_INFO_RENDER_FILES_STYLES = css`
.segment-explorer-filename-path { .segment-explorer-filename-path {
display: inline-block; display: inline-block;
&:hover {
color: var(--color-gray-1000);
text-decoration: none;
}
} }
.segment-explorer-filename-path a { .segment-explorer-filename-path a {
...@@ -161,6 +159,7 @@ export const DEV_TOOLS_INFO_RENDER_FILES_STYLES = css` ...@@ -161,6 +159,7 @@ export const DEV_TOOLS_INFO_RENDER_FILES_STYLES = css`
.segment-explorer-line { .segment-explorer-line {
white-space: pre; white-space: pre;
cursor: default;
} }
.segment-explorer-line-icon { .segment-explorer-line-icon {
......
...@@ -1014,12 +1014,13 @@ function normalizePageOrLayoutFilePath( ...@@ -1014,12 +1014,13 @@ function normalizePageOrLayoutFilePath(
projectDir: string, projectDir: string,
layoutOrPagePath: string | undefined layoutOrPagePath: string | undefined
) { ) {
const dir = projectDir /*ctx.renderOpts.dir*/ || process.cwd()
const relativePath = (layoutOrPagePath || '') const relativePath = (layoutOrPagePath || '')
// remove turbopack [project] prefix // remove turbopack [project] prefix
.replace(/^\[project\][\\/]/, '') .replace(/^\[project\][\\/]/, '')
// remove the process.cwd() prefix
.replace(process.cwd() + '/', '')
// remove the project root from the path // remove the project root from the path
.replace(dir, '') .replace(projectDir, '')
// remove /(src/)?app/ dir prefix // remove /(src/)?app/ dir prefix
.replace(/^[\\/](src[\\/])?app[\\/]/, '') .replace(/^[\\/](src[\\/])?app[\\/]/, '')
......
import { nextTestSetup } from 'e2e-utils'
import { openDevToolsIndicatorPopover } from 'next-test-utils'
describe('segment-explorer', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should render the segment explorer', async () => {
const browser = await next.browser('/parallel-routes')
// open the devtool button
await openDevToolsIndicatorPopover(browser)
// open the segment explorer
await browser.elementByCss('[data-segment-explorer]').click()
// wait for the segment explorer to be visible
await browser.waitForElementByCss('[data-nextjs-devtool-segment-explorer]')
const content = await browser.elementByCss(
'[data-nextjs-devtool-segment-explorer]'
)
expect(await content.text()).toMatchInlineSnapshot(`
"app/parallel-routes/page.tsx
app/parallel-routes/@foo/page.tsx
app/parallel-routes/@foo/layout.tsx
app/parallel-routes/@bar/page.tsx
app/parallel-routes/@bar/layout.tsx
app/parallel-routes/layout.tsx
app/layout.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