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

[segment explorer] fix route url is missing cases (#81622)

parent 1758c3c4
...@@ -40,6 +40,7 @@ import { createRouterCacheKey } from './router-reducer/create-router-cache-key' ...@@ -40,6 +40,7 @@ import { createRouterCacheKey } from './router-reducer/create-router-cache-key'
import { hasInterceptionRouteInCurrentTree } from './router-reducer/reducers/has-interception-route-in-current-tree' import { hasInterceptionRouteInCurrentTree } from './router-reducer/reducers/has-interception-route-in-current-tree'
import { dispatchAppRouterAction } from './use-action-queue' import { dispatchAppRouterAction } from './use-action-queue'
import { useRouterBFCache, type RouterBFCacheEntry } from './bfcache' import { useRouterBFCache, type RouterBFCacheEntry } from './bfcache'
import { normalizeAppPath } from '../../shared/lib/router/utils/app-paths'
const Activity = process.env.__NEXT_ROUTER_BF_CACHE const Activity = process.env.__NEXT_ROUTER_BF_CACHE
? (require('react') as typeof import('react')).unstable_Activity ? (require('react') as typeof import('react')).unstable_Activity
...@@ -616,13 +617,19 @@ export default function OuterLayoutRouter({ ...@@ -616,13 +617,19 @@ export default function OuterLayoutRouter({
: ErrorBoundary : ErrorBoundary
let segmentBoundaryTriggerNode: React.ReactNode = null let segmentBoundaryTriggerNode: React.ReactNode = null
let segmentViewStateNode: React.ReactNode = null
if ( if (
process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'production' &&
process.env.__NEXT_DEVTOOL_SEGMENT_EXPLORER process.env.__NEXT_DEVTOOL_SEGMENT_EXPLORER
) { ) {
const { SegmentBoundaryTriggerNode } = const { SegmentBoundaryTriggerNode, SegmentViewStateNode } =
require('../../next-devtools/userspace/app/segment-explorer-node') as typeof import('../../next-devtools/userspace/app/segment-explorer-node') require('../../next-devtools/userspace/app/segment-explorer-node') as typeof import('../../next-devtools/userspace/app/segment-explorer-node')
const pagePrefix = normalizeAppPath(url)
segmentViewStateNode = (
<SegmentViewStateNode key={pagePrefix} page={pagePrefix} />
)
segmentBoundaryTriggerNode = ( segmentBoundaryTriggerNode = (
<> <>
<SegmentBoundaryTriggerNode /> <SegmentBoundaryTriggerNode />
...@@ -667,6 +674,7 @@ export default function OuterLayoutRouter({ ...@@ -667,6 +674,7 @@ export default function OuterLayoutRouter({
</HTTPAccessFallbackBoundary> </HTTPAccessFallbackBoundary>
</LoadingBoundary> </LoadingBoundary>
</ErrorBoundaryComponent> </ErrorBoundaryComponent>
{segmentViewStateNode}
</ScrollAndFocusHandler> </ScrollAndFocusHandler>
} }
> >
......
...@@ -105,7 +105,6 @@ async function createComponentTreeInternal({ ...@@ -105,7 +105,6 @@ async function createComponentTreeInternal({
workStore, workStore,
componentMod: { componentMod: {
SegmentViewNode, SegmentViewNode,
SegmentViewStateNode,
HTTPAccessFallbackBoundary, HTTPAccessFallbackBoundary,
LayoutRouter, LayoutRouter,
RenderFromTemplateContext, RenderFromTemplateContext,
...@@ -800,7 +799,6 @@ async function createComponentTreeInternal({ ...@@ -800,7 +799,6 @@ async function createComponentTreeInternal({
pageElement pageElement
) )
const pagePrefix = ctx.renderOpts.page.replace(/\/page$/, '')
return [ return [
actualSegment, actualSegment,
<React.Fragment key={cacheNodeKey}> <React.Fragment key={cacheNodeKey}>
...@@ -810,7 +808,6 @@ async function createComponentTreeInternal({ ...@@ -810,7 +808,6 @@ async function createComponentTreeInternal({
<MetadataOutlet ready={getViewportReady} /> <MetadataOutlet ready={getViewportReady} />
{metadataOutlet} {metadataOutlet}
</OutletBoundary> </OutletBoundary>
<SegmentViewStateNode page={pagePrefix} />
</React.Fragment>, </React.Fragment>,
parallelRouteCacheNodeSeedData, parallelRouteCacheNodeSeedData,
loadingData, loadingData,
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { getSegmentExplorerContent, retry } from 'next-test-utils' import {
getSegmentExplorerContent,
getSegmentExplorerRoute,
retry,
} from 'next-test-utils'
describe('segment-explorer', () => { describe('segment-explorer', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
...@@ -14,6 +18,7 @@ describe('segment-explorer', () => { ...@@ -14,6 +18,7 @@ describe('segment-explorer', () => {
@bar/ [layout.tsx, page.tsx] @bar/ [layout.tsx, page.tsx]
@foo/ [layout.tsx, page.tsx]" @foo/ [layout.tsx, page.tsx]"
`) `)
expect(await getSegmentExplorerRoute(browser)).toBe('/parallel-routes')
}) })
it('should render the segment explorer for parallel routes in edge runtime', async () => { it('should render the segment explorer for parallel routes in edge runtime', async () => {
...@@ -24,6 +29,7 @@ describe('segment-explorer', () => { ...@@ -24,6 +29,7 @@ describe('segment-explorer', () => {
@bar/ [layout.tsx, page.tsx] @bar/ [layout.tsx, page.tsx]
@foo/ [layout.tsx, page.tsx]" @foo/ [layout.tsx, page.tsx]"
`) `)
expect(await getSegmentExplorerRoute(browser)).toBe('/parallel-routes-edge')
}) })
it('should render the segment explorer for nested routes', async () => { it('should render the segment explorer for nested routes', async () => {
...@@ -35,6 +41,7 @@ describe('segment-explorer', () => { ...@@ -35,6 +41,7 @@ describe('segment-explorer', () => {
~ / (overview)/ [layout.tsx] ~ / (overview)/ [layout.tsx]
grid/ [page.tsx]" grid/ [page.tsx]"
`) `)
expect(await getSegmentExplorerRoute(browser)).toBe('/blog/~/grid')
}) })
it('should cleanup on soft navigation', async () => { it('should cleanup on soft navigation', async () => {
...@@ -43,6 +50,7 @@ describe('segment-explorer', () => { ...@@ -43,6 +50,7 @@ describe('segment-explorer', () => {
"app/ [layout.tsx] "app/ [layout.tsx]
soft-navigation / a/ [page.tsx]" soft-navigation / a/ [page.tsx]"
`) `)
expect(await getSegmentExplorerRoute(browser)).toBe('/soft-navigation/a')
await browser.elementByCss('[href="/soft-navigation/b"]').click() await browser.elementByCss('[href="/soft-navigation/b"]').click()
await retry(async () => { await retry(async () => {
...@@ -53,6 +61,7 @@ describe('segment-explorer', () => { ...@@ -53,6 +61,7 @@ describe('segment-explorer', () => {
"app/ [layout.tsx] "app/ [layout.tsx]
soft-navigation / b/ [page.tsx]" soft-navigation / b/ [page.tsx]"
`) `)
expect(await getSegmentExplorerRoute(browser)).toBe('/soft-navigation/b')
}) })
it('should handle show file segments in order', async () => { it('should handle show file segments in order', async () => {
...@@ -61,6 +70,7 @@ describe('segment-explorer', () => { ...@@ -61,6 +70,7 @@ describe('segment-explorer', () => {
"app/ [layout.tsx] "app/ [layout.tsx]
(all) / file-segments/ [layout.tsx, template.tsx, page.tsx]" (all) / file-segments/ [layout.tsx, template.tsx, page.tsx]"
`) `)
expect(await getSegmentExplorerRoute(browser)).toBe('/file-segments')
}) })
it('should indicate segment explorer is not available for pages router', async () => { it('should indicate segment explorer is not available for pages router', async () => {
...@@ -73,6 +83,7 @@ describe('segment-explorer', () => { ...@@ -73,6 +83,7 @@ describe('segment-explorer', () => {
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot( expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(
`"app/ [layout.tsx, not-found.js]"` `"app/ [layout.tsx, not-found.js]"`
) )
expect(await getSegmentExplorerRoute(browser)).toBe('/404')
}) })
it('should show global-error segment', async () => { it('should show global-error segment', async () => {
...@@ -80,6 +91,8 @@ describe('segment-explorer', () => { ...@@ -80,6 +91,8 @@ describe('segment-explorer', () => {
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot( expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(
`"app/ [global-error.js]"` `"app/ [global-error.js]"`
) )
// FIXME: handle preserve the url when hitting global-error
expect(await getSegmentExplorerRoute(browser)).toBe('')
}) })
it('should show navigation boundaries of the segment', async () => { it('should show navigation boundaries of the segment', async () => {
...@@ -88,6 +101,9 @@ describe('segment-explorer', () => { ...@@ -88,6 +101,9 @@ describe('segment-explorer', () => {
"app/ [layout.tsx] "app/ [layout.tsx]
boundary/ [layout.tsx, not-found.tsx]" boundary/ [layout.tsx, not-found.tsx]"
`) `)
expect(await getSegmentExplorerRoute(browser)).toBe(
'/boundary?name=not-found'
)
await browser.loadPage(`${next.url}/boundary?name=forbidden`) await browser.loadPage(`${next.url}/boundary?name=forbidden`)
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(` expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
...@@ -116,6 +132,7 @@ describe('segment-explorer', () => { ...@@ -116,6 +132,7 @@ describe('segment-explorer', () => {
"app/ [layout.tsx] "app/ [layout.tsx]
search/ [layout.tsx, loading.tsx]" search/ [layout.tsx, loading.tsx]"
`) `)
expect(await getSegmentExplorerRoute(browser)).toBe('/search?q=abc')
}) })
it('should show the custom error boundary when present', async () => { it('should show the custom error boundary when present', async () => {
...@@ -124,6 +141,9 @@ describe('segment-explorer', () => { ...@@ -124,6 +141,9 @@ describe('segment-explorer', () => {
"app/ [layout.tsx] "app/ [layout.tsx]
runtime-error / boundary/ [error.tsx]" runtime-error / boundary/ [error.tsx]"
`) `)
expect(await getSegmentExplorerRoute(browser)).toBe(
'/runtime-error/boundary'
)
}) })
it('should display parallel routes default page when present', async () => { it('should display parallel routes default page when present', async () => {
...@@ -135,6 +155,9 @@ describe('segment-explorer', () => { ...@@ -135,6 +155,9 @@ describe('segment-explorer', () => {
subroute/ [page.tsx] subroute/ [page.tsx]
@foo/ [default.tsx]" @foo/ [default.tsx]"
`) `)
expect(await getSegmentExplorerRoute(browser)).toBe(
'/parallel-default/subroute'
)
}) })
it('should display boundary selector when a segment has only boundary files', async () => { it('should display boundary selector when a segment has only boundary files', async () => {
...@@ -145,5 +168,16 @@ describe('segment-explorer', () => { ...@@ -145,5 +168,16 @@ describe('segment-explorer', () => {
framework/ [layout.tsx] framework/ [layout.tsx]
blog/ [layout.tsx, page.tsx]" blog/ [layout.tsx, page.tsx]"
`) `)
expect(await getSegmentExplorerRoute(browser)).toBe(
'/no-layout/framework/blog'
)
})
it('should render route for index page', async () => {
const browser = await next.browser('/')
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(
`"app/ [layout.tsx, page.tsx]"`
)
expect(await getSegmentExplorerRoute(browser)).toBe('/')
}) })
}) })
...@@ -237,13 +237,13 @@ describe('Dynamic IO Errors', () => { ...@@ -237,13 +237,13 @@ describe('Dynamic IO Errors', () => {
at ScrollAndFocusHandler (webpack://<next-src>) at ScrollAndFocusHandler (webpack://<next-src>)
at RenderFromTemplateContext (webpack://<next-src>) at RenderFromTemplateContext (webpack://<next-src>)
at OuterLayoutRouter (webpack://<next-src>) at OuterLayoutRouter (webpack://<next-src>)
332 | */ 333 | */
333 | function InnerLayoutRouter({ 334 | function InnerLayoutRouter({
> 334 | tree, > 335 | tree,
| ^ | ^
335 | segmentPath, 336 | segmentPath,
336 | cacheNode, 337 | cacheNode,
337 | url, 338 | url,
To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/dynamic-metadata-error-route" in your browser to investigate the error. To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/dynamic-metadata-error-route" in your browser to investigate the error.
Error occurred prerendering page "/dynamic-metadata-error-route". Read more: https://nextjs.org/docs/messages/prerender-error Error occurred prerendering page "/dynamic-metadata-error-route". Read more: https://nextjs.org/docs/messages/prerender-error
...@@ -739,13 +739,13 @@ describe('Dynamic IO Errors', () => { ...@@ -739,13 +739,13 @@ describe('Dynamic IO Errors', () => {
at ScrollAndFocusHandler (webpack://<next-src>) at ScrollAndFocusHandler (webpack://<next-src>)
at RenderFromTemplateContext (webpack://<next-src>) at RenderFromTemplateContext (webpack://<next-src>)
at OuterLayoutRouter (webpack://<next-src>) at OuterLayoutRouter (webpack://<next-src>)
332 | */ 333 | */
333 | function InnerLayoutRouter({ 334 | function InnerLayoutRouter({
> 334 | tree, > 335 | tree,
| ^ | ^
335 | segmentPath, 336 | segmentPath,
336 | cacheNode, 337 | cacheNode,
337 | url, 338 | url,
To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/dynamic-root" in your browser to investigate the error. To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/dynamic-root" in your browser to investigate the error.
Error occurred prerendering page "/dynamic-root". Read more: https://nextjs.org/docs/messages/prerender-error Error occurred prerendering page "/dynamic-root". Read more: https://nextjs.org/docs/messages/prerender-error
...@@ -1860,13 +1860,13 @@ describe('Dynamic IO Errors', () => { ...@@ -1860,13 +1860,13 @@ describe('Dynamic IO Errors', () => {
at ScrollAndFocusHandler (webpack://<next-src>) at ScrollAndFocusHandler (webpack://<next-src>)
at RenderFromTemplateContext (<anonymous>) at RenderFromTemplateContext (<anonymous>)
at OuterLayoutRouter (webpack://<next-src>) at OuterLayoutRouter (webpack://<next-src>)
332 | */ 333 | */
333 | function InnerLayoutRouter({ 334 | function InnerLayoutRouter({
> 334 | tree, > 335 | tree,
| ^ | ^
335 | segmentPath, 336 | segmentPath,
336 | cacheNode, 337 | cacheNode,
337 | url, 338 | url,
To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/sync-attribution/unguarded-async-guarded-clientsync" in your browser to investigate the error. To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/sync-attribution/unguarded-async-guarded-clientsync" in your browser to investigate the error.
Error occurred prerendering page "/sync-attribution/unguarded-async-guarded-clientsync". Read more: https://nextjs.org/docs/messages/prerender-error Error occurred prerendering page "/sync-attribution/unguarded-async-guarded-clientsync". Read more: https://nextjs.org/docs/messages/prerender-error
......
...@@ -13,7 +13,7 @@ const EXTERNAL = { ...@@ -13,7 +13,7 @@ const EXTERNAL = {
const COLLECTOR_PORT = 9001 const COLLECTOR_PORT = 9001
describe('opentelemetry', () => { describe('opentelemetry', () => {
const { next, skipped, isNextDev } = nextTestSetup({ const { next, skipped } = nextTestSetup({
files: __dirname, files: __dirname,
skipDeployment: true, skipDeployment: true,
dependencies: require('./package.json').dependencies, dependencies: require('./package.json').dependencies,
...@@ -170,7 +170,7 @@ describe('opentelemetry', () => { ...@@ -170,7 +170,7 @@ describe('opentelemetry', () => {
}, },
{ {
attributes: { attributes: {
'next.clientComponentLoadCount': isNextDev ? 8 : 7, 'next.clientComponentLoadCount': 7,
'next.span_type': 'next.span_type':
'NextNodeServer.clientComponentLoading', 'NextNodeServer.clientComponentLoading',
}, },
......
...@@ -962,6 +962,12 @@ export async function openDevToolsIndicatorPopover( ...@@ -962,6 +962,12 @@ export async function openDevToolsIndicatorPopover(
} }
} }
export async function getSegmentExplorerRoute(browser: Playwright) {
return await browser
.elementByCss('.segment-explorer-page-route-bar-path')
.text()
}
export async function getSegmentExplorerContent(browser: Playwright) { export async function getSegmentExplorerContent(browser: Playwright) {
// open the devtool button // open the devtool button
await openDevToolsIndicatorPopover(browser) await openDevToolsIndicatorPopover(browser)
......
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