Skip to content

Commit c383d29

Browse files
committed
Fix Activity boundary names
Follow-up to #85155. Made a mistake in the context-passing logic.
1 parent da024c1 commit c383d29

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

packages/next/src/client/components/layout-router.tsx

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import { hasInterceptionRouteInCurrentTree } from './router-reducer/reducers/has
4444
import { dispatchAppRouterAction } from './use-action-queue'
4545
import { useRouterBFCache, type RouterBFCacheEntry } from './bfcache'
4646
import { normalizeAppPath } from '../../shared/lib/router/utils/app-paths'
47-
import { PAGE_SEGMENT_KEY } from '../../shared/lib/segment'
4847
import {
4948
NavigationPromisesContext,
5049
type NavigationPromises,
@@ -348,7 +347,7 @@ function InnerLayoutRouter({
348347
}: {
349348
tree: FlightRouterState
350349
segmentPath: FlightSegmentPath
351-
debugNameContext: ActivityProps['name']
350+
debugNameContext: string
352351
cacheNode: CacheNode
353352
params: Params
354353
url: string
@@ -584,7 +583,7 @@ export default function OuterLayoutRouter({
584583
parentParams,
585584
url,
586585
isActive,
587-
debugNameContext: parentDebugNameContext,
586+
debugNameContext,
588587
} = context
589588

590589
// Get the CacheNode for this segment by reading it from the parent segment's
@@ -706,9 +705,20 @@ export default function OuterLayoutRouter({
706705

707706
const debugName = getBoundaryDebugNameFromSegment(segment)
708707
// `debugNameContext` represents the nearest non-"virtual" parent segment.
709-
// `getBoundaryDebugNameFromSegment` returns null for virtual segments.
710-
// So if `debugName` is null, the context is passed through unchanged.
711-
const debugNameContext = debugName ?? parentDebugNameContext
708+
// `getBoundaryDebugNameFromSegment` returns undefined for virtual segments.
709+
// So if `debugName` is undefined, the context is passed through unchanged.
710+
const childDebugNameContext = debugName ?? debugNameContext
711+
712+
// In practical terms, clicking this name in the Suspense DevTools
713+
// should select the child slots of that layout.
714+
//
715+
// So the name we apply to the Activity boundary is actually based on
716+
// the nearest parent segments.
717+
//
718+
// We skip over "virtual" parents, i.e. ones inserted by Next.js that
719+
// don't correspond to application-defined code.
720+
const isVirtual = debugName === undefined
721+
const debugNameToDisplay = isVirtual ? undefined : debugNameContext
712722

713723
// TODO: The loading module data for a segment is stored on the parent, then
714724
// applied to each of that parent segment's parallel route slots. In the
@@ -729,7 +739,10 @@ export default function OuterLayoutRouter({
729739
errorStyles={errorStyles}
730740
errorScripts={errorScripts}
731741
>
732-
<LoadingBoundary name={debugName} loading={loadingModuleData}>
742+
<LoadingBoundary
743+
name={debugNameToDisplay}
744+
loading={loadingModuleData}
745+
>
733746
<HTTPAccessFallbackBoundary
734747
notFound={notFound}
735748
forbidden={forbidden}
@@ -742,7 +755,7 @@ export default function OuterLayoutRouter({
742755
params={params}
743756
cacheNode={cacheNode}
744757
segmentPath={segmentPath}
745-
debugNameContext={debugNameContext}
758+
debugNameContext={childDebugNameContext}
746759
isActive={isActive && stateKey === activeStateKey}
747760
/>
748761
{segmentBoundaryTriggerNode}
@@ -775,15 +788,7 @@ export default function OuterLayoutRouter({
775788
if (process.env.__NEXT_CACHE_COMPONENTS) {
776789
child = (
777790
<Activity
778-
// In practical terms, clicking this name in the Suspense DevTools
779-
// should select the child slots of that layout.
780-
//
781-
// So the name we apply to the Activity boundary is actually based on
782-
// the nearest parent segments.
783-
//
784-
// We skip over "virtual" parents, i.e. ones inserted by Next.js that
785-
// don't correspond to application-defined code.
786-
name={debugNameContext}
791+
name={debugNameToDisplay}
787792
key={stateKey}
788793
mode={stateKey === activeStateKey ? 'visible' : 'hidden'}
789794
>
@@ -821,12 +826,6 @@ function isVirtualLayout(segment: string): boolean {
821826
// This is inserted by the loader. We should consider encoding these
822827
// in a more special way instead of checking the name, to distinguish them
823828
// from app-defined groups.
824-
segment === '(slot)' ||
825-
// For some reason, the loader tree sometimes includes extra __PAGE__
826-
// "layouts" when part of a parallel route. But it's not a leaf node.
827-
// Otherwise, we wouldn't need this special case because pages are
828-
// always leaf nodes.
829-
// TODO: Investigate why the loader produces these fake page segments.
830-
segment.startsWith(PAGE_SEGMENT_KEY)
829+
segment === '(slot)'
831830
)
832831
}

packages/next/src/shared/lib/app-router-context.shared-runtime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const LayoutRouterContext = React.createContext<{
6363
parentCacheNode: CacheNode
6464
parentSegmentPath: FlightSegmentPath | null
6565
parentParams: Params
66-
debugNameContext: string | undefined
66+
debugNameContext: string
6767
url: string
6868
isActive: boolean
6969
} | null>(null)

0 commit comments

Comments
 (0)