Commit d2207067 authored by Jiachi Liu's avatar Jiachi Liu Committed by RobPruzan

fix render files and update snapshot

parent 06bef45f
......@@ -120,7 +120,7 @@ export function SegmentBoundaryTrigger({
const hasBoundaries = Object.values(boundaries).some(
(boundary) => boundary !== null
)
const isPageFile = fileType === 'page'
const isPageOrBoundary = fileType && !isBoundaryFile(fileType)
const openInEditor = useCallback(({ filePath }: { filePath: string }) => {
const params = new URLSearchParams({
......@@ -158,7 +158,10 @@ export function SegmentBoundaryTrigger({
)
// For non-page files, just render a simple button to open in editor
if (fileType !== 'page' && !fileType.startsWith('boundary:')) {
if (
!(fileType === 'page' || fileType === 'default') &&
!isBoundaryFile(fileType)
) {
return (
<button
className="segment-boundary-trigger"
......@@ -172,11 +175,6 @@ export function SegmentBoundaryTrigger({
)
}
// Don't render the dropdown if there are no boundaries and no page file
if (!hasBoundaries && !isPageFile) {
return null
}
const Trigger = (
triggerProps: React.ComponentProps<'button'> & {
ref?: React.Ref<HTMLButtonElement>
......@@ -187,7 +185,7 @@ export function SegmentBoundaryTrigger({
return (
<button {...triggerProps} ref={mergedRef} type="button">
<span className="segment-boundary-trigger-text">
{isPageFile
{isPageOrBoundary
? pageFileName
: boundaryType === null
? // TODO(pran): improve the UX of the default boundary selector
......@@ -206,7 +204,7 @@ export function SegmentBoundaryTrigger({
<Menu.Trigger
className={cx(
'segment-boundary-trigger',
!isPageFile && 'segment-boundary-trigger--boundary',
!isPageOrBoundary && 'segment-boundary-trigger--boundary',
isOverridden && 'segment-boundary-trigger--overridden'
)}
data-nextjs-dev-overlay-segment-boundary-trigger-button
......
......@@ -11,7 +11,9 @@ import {
import { Tooltip } from '../../../components/tooltip'
import { useRef, useState, useCallback, useMemo } from 'react'
import {
BOUNDARY_PREFIX,
BUILTIN_PREFIX,
isBoundaryFile,
normalizeBoundaryFilename,
} from '../../../../server/app-render/segment-explorer-path'
......@@ -43,7 +45,7 @@ function countActiveBoundaries(node: SegmentTrieNode): number {
if (
node.value?.setBoundaryType &&
node.value.boundaryType !== null &&
!node.value.type.startsWith('boundary:')
!isBoundaryFile(node.value.type)
) {
count++
}
......@@ -178,6 +180,12 @@ function PageSegmentTreeLayerPresentation({
if (aType === 'template' && bType !== 'template') return -1
if (aType !== 'template' && bType === 'template') return 1
// non boundary files are prioritized than boundary files
if (aType && bType) {
if (isBoundaryFile(aType) && !isBoundaryFile(bType)) return 1
if (!isBoundaryFile(aType) && isBoundaryFile(bType)) return -1
}
// If both are the same type, sort by pagePath
const aFilePath = node.children[a]?.value?.pagePath || ''
const bFilePath = node.children[b]?.value?.pagePath || ''
......@@ -225,7 +233,7 @@ function PageSegmentTreeLayerPresentation({
filesChildrenKeys.forEach((childKey) => {
const childNode = node.children[childKey]
if (!childNode || !childNode.value) return
if (childNode.value.type.startsWith('boundary:')) {
if (isBoundaryFile(childNode.value.type)) {
const boundaryType = childNode.value.type.split(':')[1] as
| 'not-found'
| 'loading'
......@@ -243,7 +251,7 @@ function PageSegmentTreeLayerPresentation({
if (!childNode || !childNode.value) return true
const type = childNode.value.type
const selectedBoundaryType = firstChild?.value?.type?.replace(
'boundary:',
BOUNDARY_PREFIX,
''
)
if (
......@@ -294,7 +302,7 @@ function PageSegmentTreeLayerPresentation({
}
// If it's boundary node, which marks the existence of the boundary not the rendered status,
// we don't need to present in the rendered files.
if (childNode.value.type.startsWith('boundary:')) {
if (isBoundaryFile(childNode.value.type)) {
return null
}
// If it's a page file, don't show it as a separate label since it's represented by the dropdown button
......
......@@ -26,7 +26,11 @@ import type {
UseCachePageComponentProps,
} from '../use-cache/use-cache-wrapper'
import { DEFAULT_SEGMENT_KEY } from '../../shared/lib/segment'
import { getConventionPathByType } from './segment-explorer-path'
import {
BOUNDARY_PREFIX,
BOUNDARY_SUFFIX,
getConventionPathByType,
} from './segment-explorer-path'
/**
* Use the provided loader tree to create the React Component tree.
......@@ -562,24 +566,24 @@ async function createComponentTreeInternal({
// Add a suffix to avoid conflict with the segment view node representing rendered file.
// existence: not-found.tsx@boundary
// rendered: not-found.tsx
const fileNameSuffix = '@boundary'
const fileNameSuffix = BOUNDARY_SUFFIX
const segmentViewBoundaries = isSegmentViewEnabled ? (
<>
{notFoundFilePath && (
<SegmentViewNode
type={'boundary:not-found'}
type={`${BOUNDARY_PREFIX}not-found`}
pagePath={notFoundFilePath + fileNameSuffix}
/>
)}
{loadingFilePath && (
<SegmentViewNode
type={'boundary:loading'}
type={`${BOUNDARY_PREFIX}loading`}
pagePath={loadingFilePath + fileNameSuffix}
/>
)}
{errorFilePath && (
<SegmentViewNode
type={'boundary:error'}
type={`${BOUNDARY_PREFIX}error`}
pagePath={errorFilePath + fileNameSuffix}
/>
)}
......
......@@ -30,10 +30,16 @@ export function normalizeConventionFilePath(
return relativePath
}
export const BOUNDARY_SUFFIX = '@boundary'
export function normalizeBoundaryFilename(filename: string) {
return filename
.replace(new RegExp(`^${BUILTIN_PREFIX}`), '')
.replace(/@boundary$/, '')
.replace(new RegExp(`${BOUNDARY_SUFFIX}$`), '')
}
export const BOUNDARY_PREFIX = 'boundary:'
export function isBoundaryFile(fileType: string) {
return fileType.startsWith(BOUNDARY_PREFIX)
}
export function getConventionPathByType(
......
......@@ -28,15 +28,16 @@ describe('segment-explorer', () => {
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/
layout.tsx
boundary
parallel-routes/
layout.tsx
page.tsx
@bar/
layout.tsx
page.tsx
boundary
@foo/
layout.tsx
page.tsx"
boundary"
`)
})
......@@ -45,6 +46,7 @@ describe('segment-explorer', () => {
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/
layout.tsx
boundary
parallel-routes-edge/
layout.tsx
page.tsx
......@@ -62,6 +64,7 @@ describe('segment-explorer', () => {
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/
layout.tsx
boundary
(v2)/
layout.tsx
blog / (team)/
......@@ -79,6 +82,7 @@ describe('segment-explorer', () => {
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/
layout.tsx
boundary
soft-navigation / a/
page.tsx"
`)
......@@ -91,6 +95,7 @@ describe('segment-explorer', () => {
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/
layout.tsx
boundary
soft-navigation / b/
page.tsx"
`)
......@@ -101,6 +106,7 @@ describe('segment-explorer', () => {
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/
layout.tsx
boundary
(all) / file-segments/
layout.tsx
template.tsx
......@@ -137,27 +143,32 @@ describe('segment-explorer', () => {
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/
layout.tsx
boundary
boundary/
layout.tsx
not-found.tsx"
boundary"
`)
await browser.loadPage(`${next.url}/boundary?name=forbidden`)
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/
layout.tsx
boundary
boundary/
layout.tsx
forbidden.tsx"
forbidden.tsx
boundary"
`)
await browser.loadPage(`${next.url}/boundary?name=unauthorized`)
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/
layout.tsx
boundary
boundary/
layout.tsx
unauthorized.tsx"
unauthorized.tsx
boundary"
`)
})
......@@ -174,9 +185,10 @@ describe('segment-explorer', () => {
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/
layout.tsx
boundary
search/
layout.tsx
loading.tsx"
boundary"
`)
})
......@@ -185,8 +197,9 @@ describe('segment-explorer', () => {
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/
layout.tsx
boundary
runtime-error / boundary/
error.tsx"
boundary"
`)
})
......@@ -195,6 +208,7 @@ describe('segment-explorer', () => {
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/
layout.tsx
boundary
parallel-default/
layout.tsx
default.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