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