Unverified Commit 077da103 authored by Andrew Clark's avatar Andrew Clark Committed by GitHub

Fix Activity boundary names (#85185)

Follow-up to #85155. Made a mistake in the context-passing logic.
parent 409b2810
...@@ -44,7 +44,6 @@ import { hasInterceptionRouteInCurrentTree } from './router-reducer/reducers/has ...@@ -44,7 +44,6 @@ import { hasInterceptionRouteInCurrentTree } from './router-reducer/reducers/has
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' import { normalizeAppPath } from '../../shared/lib/router/utils/app-paths'
import { PAGE_SEGMENT_KEY } from '../../shared/lib/segment'
import { import {
NavigationPromisesContext, NavigationPromisesContext,
type NavigationPromises, type NavigationPromises,
...@@ -348,7 +347,7 @@ function InnerLayoutRouter({ ...@@ -348,7 +347,7 @@ function InnerLayoutRouter({
}: { }: {
tree: FlightRouterState tree: FlightRouterState
segmentPath: FlightSegmentPath segmentPath: FlightSegmentPath
debugNameContext: ActivityProps['name'] debugNameContext: string
cacheNode: CacheNode cacheNode: CacheNode
params: Params params: Params
url: string url: string
...@@ -584,7 +583,7 @@ export default function OuterLayoutRouter({ ...@@ -584,7 +583,7 @@ export default function OuterLayoutRouter({
parentParams, parentParams,
url, url,
isActive, isActive,
debugNameContext: parentDebugNameContext, debugNameContext,
} = context } = context
// Get the CacheNode for this segment by reading it from the parent segment's // Get the CacheNode for this segment by reading it from the parent segment's
...@@ -706,9 +705,20 @@ export default function OuterLayoutRouter({ ...@@ -706,9 +705,20 @@ export default function OuterLayoutRouter({
const debugName = getBoundaryDebugNameFromSegment(segment) const debugName = getBoundaryDebugNameFromSegment(segment)
// `debugNameContext` represents the nearest non-"virtual" parent segment. // `debugNameContext` represents the nearest non-"virtual" parent segment.
// `getBoundaryDebugNameFromSegment` returns null for virtual segments. // `getBoundaryDebugNameFromSegment` returns undefined for virtual segments.
// So if `debugName` is null, the context is passed through unchanged. // So if `debugName` is undefined, the context is passed through unchanged.
const debugNameContext = debugName ?? parentDebugNameContext const childDebugNameContext = debugName ?? debugNameContext
// In practical terms, clicking this name in the Suspense DevTools
// should select the child slots of that layout.
//
// So the name we apply to the Activity boundary is actually based on
// the nearest parent segments.
//
// We skip over "virtual" parents, i.e. ones inserted by Next.js that
// don't correspond to application-defined code.
const isVirtual = debugName === undefined
const debugNameToDisplay = isVirtual ? undefined : debugNameContext
// TODO: The loading module data for a segment is stored on the parent, then // TODO: The loading module data for a segment is stored on the parent, then
// applied to each of that parent segment's parallel route slots. In the // applied to each of that parent segment's parallel route slots. In the
...@@ -729,7 +739,10 @@ export default function OuterLayoutRouter({ ...@@ -729,7 +739,10 @@ export default function OuterLayoutRouter({
errorStyles={errorStyles} errorStyles={errorStyles}
errorScripts={errorScripts} errorScripts={errorScripts}
> >
<LoadingBoundary name={debugName} loading={loadingModuleData}> <LoadingBoundary
name={debugNameToDisplay}
loading={loadingModuleData}
>
<HTTPAccessFallbackBoundary <HTTPAccessFallbackBoundary
notFound={notFound} notFound={notFound}
forbidden={forbidden} forbidden={forbidden}
...@@ -742,7 +755,7 @@ export default function OuterLayoutRouter({ ...@@ -742,7 +755,7 @@ export default function OuterLayoutRouter({
params={params} params={params}
cacheNode={cacheNode} cacheNode={cacheNode}
segmentPath={segmentPath} segmentPath={segmentPath}
debugNameContext={debugNameContext} debugNameContext={childDebugNameContext}
isActive={isActive && stateKey === activeStateKey} isActive={isActive && stateKey === activeStateKey}
/> />
{segmentBoundaryTriggerNode} {segmentBoundaryTriggerNode}
...@@ -775,15 +788,7 @@ export default function OuterLayoutRouter({ ...@@ -775,15 +788,7 @@ export default function OuterLayoutRouter({
if (process.env.__NEXT_CACHE_COMPONENTS) { if (process.env.__NEXT_CACHE_COMPONENTS) {
child = ( child = (
<Activity <Activity
// In practical terms, clicking this name in the Suspense DevTools name={debugNameToDisplay}
// should select the child slots of that layout.
//
// So the name we apply to the Activity boundary is actually based on
// the nearest parent segments.
//
// We skip over "virtual" parents, i.e. ones inserted by Next.js that
// don't correspond to application-defined code.
name={debugNameContext}
key={stateKey} key={stateKey}
mode={stateKey === activeStateKey ? 'visible' : 'hidden'} mode={stateKey === activeStateKey ? 'visible' : 'hidden'}
> >
...@@ -821,12 +826,6 @@ function isVirtualLayout(segment: string): boolean { ...@@ -821,12 +826,6 @@ function isVirtualLayout(segment: string): boolean {
// This is inserted by the loader. We should consider encoding these // This is inserted by the loader. We should consider encoding these
// in a more special way instead of checking the name, to distinguish them // in a more special way instead of checking the name, to distinguish them
// from app-defined groups. // from app-defined groups.
segment === '(slot)' || segment === '(slot)'
// For some reason, the loader tree sometimes includes extra __PAGE__
// "layouts" when part of a parallel route. But it's not a leaf node.
// Otherwise, we wouldn't need this special case because pages are
// always leaf nodes.
// TODO: Investigate why the loader produces these fake page segments.
segment.startsWith(PAGE_SEGMENT_KEY)
) )
} }
...@@ -63,7 +63,7 @@ export const LayoutRouterContext = React.createContext<{ ...@@ -63,7 +63,7 @@ export const LayoutRouterContext = React.createContext<{
parentCacheNode: CacheNode parentCacheNode: CacheNode
parentSegmentPath: FlightSegmentPath | null parentSegmentPath: FlightSegmentPath | null
parentParams: Params parentParams: Params
debugNameContext: string | undefined debugNameContext: string
url: string url: string
isActive: boolean isActive: boolean
} | null>(null) } | null>(null)
......
...@@ -17,7 +17,7 @@ describe('hydration-error-count', () => { ...@@ -17,7 +17,7 @@ describe('hydration-error-count', () => {
<ScrollAndFocusHandler segmentPath={[...]}> <ScrollAndFocusHandler segmentPath={[...]}>
<InnerScrollAndFocusHandler segmentPath={[...]} focusAndScrollRef={{apply:false, ...}}> <InnerScrollAndFocusHandler segmentPath={[...]} focusAndScrollRef={{apply:false, ...}}>
<ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}> <ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}>
<LoadingBoundary name={undefined} loading={null}> <LoadingBoundary name="bad-nesting/" loading={null}>
<HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}> <HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}>
<RedirectBoundary> <RedirectBoundary>
<RedirectErrorBoundary router={{...}}> <RedirectErrorBoundary router={{...}}>
...@@ -66,7 +66,7 @@ describe('hydration-error-count', () => { ...@@ -66,7 +66,7 @@ describe('hydration-error-count', () => {
<ScrollAndFocusHandler segmentPath={[...]}> <ScrollAndFocusHandler segmentPath={[...]}>
<InnerScrollAndFocusHandler segmentPath={[...]} focusAndScrollRef={{apply:false, ...}}> <InnerScrollAndFocusHandler segmentPath={[...]} focusAndScrollRef={{apply:false, ...}}>
<ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}> <ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}>
<LoadingBoundary name={undefined} loading={null}> <LoadingBoundary name="bad-nesting/" loading={null}>
<HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}> <HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}>
<RedirectBoundary> <RedirectBoundary>
<RedirectErrorBoundary router={{...}}> <RedirectErrorBoundary router={{...}}>
...@@ -120,7 +120,7 @@ describe('hydration-error-count', () => { ...@@ -120,7 +120,7 @@ describe('hydration-error-count', () => {
<ScrollAndFocusHandler segmentPath={[...]}> <ScrollAndFocusHandler segmentPath={[...]}>
<InnerScrollAndFocusHandler segmentPath={[...]} focusAndScrollRef={{apply:false, ...}}> <InnerScrollAndFocusHandler segmentPath={[...]} focusAndScrollRef={{apply:false, ...}}>
<ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}> <ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}>
<LoadingBoundary name={undefined} loading={null}> <LoadingBoundary name="html-diff/" loading={null}>
<HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}> <HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}>
<RedirectBoundary> <RedirectBoundary>
<RedirectErrorBoundary router={{...}}> <RedirectErrorBoundary router={{...}}>
...@@ -155,7 +155,7 @@ describe('hydration-error-count', () => { ...@@ -155,7 +155,7 @@ describe('hydration-error-count', () => {
<ScrollAndFocusHandler segmentPath={[...]}> <ScrollAndFocusHandler segmentPath={[...]}>
<InnerScrollAndFocusHandler segmentPath={[...]} focusAndScrollRef={{apply:false, ...}}> <InnerScrollAndFocusHandler segmentPath={[...]} focusAndScrollRef={{apply:false, ...}}>
<ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}> <ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}>
<LoadingBoundary name={undefined} loading={null}> <LoadingBoundary name="html-diff/" loading={null}>
<HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}> <HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}>
<RedirectBoundary> <RedirectBoundary>
<RedirectErrorBoundary router={{...}}> <RedirectErrorBoundary router={{...}}>
...@@ -197,7 +197,7 @@ describe('hydration-error-count', () => { ...@@ -197,7 +197,7 @@ describe('hydration-error-count', () => {
<ScrollAndFocusHandler segmentPath={[...]}> <ScrollAndFocusHandler segmentPath={[...]}>
<InnerScrollAndFocusHandler segmentPath={[...]} focusAndScrollRef={{apply:false, ...}}> <InnerScrollAndFocusHandler segmentPath={[...]} focusAndScrollRef={{apply:false, ...}}>
<ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}> <ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}>
<LoadingBoundary name={undefined} loading={null}> <LoadingBoundary name="two-issues/" loading={null}>
<HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}> <HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}>
<RedirectBoundary> <RedirectBoundary>
<RedirectErrorBoundary router={{...}}> <RedirectErrorBoundary router={{...}}>
...@@ -229,7 +229,7 @@ describe('hydration-error-count', () => { ...@@ -229,7 +229,7 @@ describe('hydration-error-count', () => {
<ScrollAndFocusHandler segmentPath={[...]}> <ScrollAndFocusHandler segmentPath={[...]}>
<InnerScrollAndFocusHandler segmentPath={[...]} focusAndScrollRef={{apply:false, ...}}> <InnerScrollAndFocusHandler segmentPath={[...]} focusAndScrollRef={{apply:false, ...}}>
<ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}> <ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}>
<LoadingBoundary name={undefined} loading={null}> <LoadingBoundary name="two-issues/" loading={null}>
<HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}> <HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}>
<RedirectBoundary> <RedirectBoundary>
<RedirectErrorBoundary router={{...}}> <RedirectErrorBoundary router={{...}}>
...@@ -267,7 +267,7 @@ describe('hydration-error-count', () => { ...@@ -267,7 +267,7 @@ describe('hydration-error-count', () => {
<ScrollAndFocusHandler segmentPath={[...]}> <ScrollAndFocusHandler segmentPath={[...]}>
<InnerScrollAndFocusHandler segmentPath={[...]} focusAndScrollRef={{apply:false, ...}}> <InnerScrollAndFocusHandler segmentPath={[...]} focusAndScrollRef={{apply:false, ...}}>
<ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}> <ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}>
<LoadingBoundary name={undefined} loading={null}> <LoadingBoundary name="two-issues/" loading={null}>
<HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}> <HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}>
<RedirectBoundary> <RedirectBoundary>
<RedirectErrorBoundary router={{...}}> <RedirectErrorBoundary router={{...}}>
...@@ -299,7 +299,7 @@ describe('hydration-error-count', () => { ...@@ -299,7 +299,7 @@ describe('hydration-error-count', () => {
<ScrollAndFocusHandler segmentPath={[...]}> <ScrollAndFocusHandler segmentPath={[...]}>
<InnerScrollAndFocusHandler segmentPath={[...]} focusAndScrollRef={{apply:false, ...}}> <InnerScrollAndFocusHandler segmentPath={[...]} focusAndScrollRef={{apply:false, ...}}>
<ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}> <ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}>
<LoadingBoundary name={undefined} loading={null}> <LoadingBoundary name="two-issues/" loading={null}>
<HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}> <HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}>
<RedirectBoundary> <RedirectBoundary>
<RedirectErrorBoundary router={{...}}> <RedirectErrorBoundary router={{...}}>
...@@ -343,7 +343,7 @@ describe('hydration-error-count', () => { ...@@ -343,7 +343,7 @@ describe('hydration-error-count', () => {
<ScrollAndFocusHandler segmentPath={[...]}> <ScrollAndFocusHandler segmentPath={[...]}>
<InnerScrollAndFocusHandler segmentPath={[...]} focusAndScrollRef={{apply:false, ...}}> <InnerScrollAndFocusHandler segmentPath={[...]} focusAndScrollRef={{apply:false, ...}}>
<ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}> <ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}>
<LoadingBoundary name={undefined} loading={null}> <LoadingBoundary name="hydration-..." loading={null}>
<HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}> <HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}>
<RedirectBoundary> <RedirectBoundary>
<RedirectErrorBoundary router={{...}}> <RedirectErrorBoundary router={{...}}>
......
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