Unverified Commit 66094ef6 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Ensure rootLayoutIncluded is set on partial render (#44958)

parent 8a8a70e4
......@@ -1148,7 +1148,7 @@ export async function renderToHTMLOrFlight(
createSegmentPath: CreateSegmentPath
loaderTree: LoaderTree
parentParams: { [key: string]: any }
rootLayoutIncluded?: boolean
rootLayoutIncluded: boolean
firstItem?: boolean
}): Promise<{ Component: React.ComponentType }> => {
const layoutOrPagePath = layout?.[1] || page?.[1]
......@@ -1500,6 +1500,7 @@ export async function renderToHTMLOrFlight(
flightRouterState,
parentRendered,
rscPayloadHead,
rootLayoutIncluded,
}: {
createSegmentPath: CreateSegmentPath
loaderTreeToFilter: LoaderTree
......@@ -1508,10 +1509,22 @@ export async function renderToHTMLOrFlight(
flightRouterState?: FlightRouterState
parentRendered?: boolean
rscPayloadHead: React.ReactNode
rootLayoutIncluded: boolean
}): Promise<FlightDataPath> => {
const [segment, parallelRoutes] = loaderTreeToFilter
const [segment, parallelRoutes, { layout }] = loaderTreeToFilter
const isLayout = typeof layout !== 'undefined'
const parallelRoutesKeys = Object.keys(parallelRoutes)
/**
* Checks if the current segment is a root layout.
*/
const rootLayoutAtThisLevel = isLayout && !rootLayoutIncluded
/**
* Checks if the current segment or any level above it has a root layout.
*/
const rootLayoutIncludedAtThisLevelOrAbove =
rootLayoutIncluded || rootLayoutAtThisLevel
// Because this function walks to a deeper point in the tree to start rendering we have to track the dynamic parameters up to the point where rendering starts
const segmentParam = getDynamicParamFromSegment(segment)
const currentParams =
......@@ -1559,6 +1572,8 @@ export async function renderToHTMLOrFlight(
loaderTree: loaderTreeToFilter,
parentParams: currentParams,
firstItem: isFirst,
// This is intentionally not "rootLayoutIncludedAtThisLevelOrAbove" as createComponentTree starts at the current level and does a check for "rootLayoutAtThisLevel" too.
rootLayoutIncluded: rootLayoutIncluded,
}
)
return <Component />
......@@ -1588,6 +1603,7 @@ export async function renderToHTMLOrFlight(
parentRendered: parentRendered || renderComponentsOnThisLevel,
isFirst: false,
rscPayloadHead,
rootLayoutIncluded: rootLayoutIncludedAtThisLevelOrAbove,
})
if (typeof path[path.length - 1] !== 'string') {
......@@ -1610,6 +1626,7 @@ export async function renderToHTMLOrFlight(
flightRouterState: providedFlightRouterState,
isFirst: true,
rscPayloadHead,
rootLayoutIncluded: false,
})
).slice(1),
]
......@@ -1688,6 +1705,7 @@ export async function renderToHTMLOrFlight(
loaderTree: loaderTree,
parentParams: {},
firstItem: true,
rootLayoutIncluded: false,
})
const initialTree = createFlightRouterStateFromLoaderTree(loaderTree)
......
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