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( ...@@ -1148,7 +1148,7 @@ export async function renderToHTMLOrFlight(
createSegmentPath: CreateSegmentPath createSegmentPath: CreateSegmentPath
loaderTree: LoaderTree loaderTree: LoaderTree
parentParams: { [key: string]: any } parentParams: { [key: string]: any }
rootLayoutIncluded?: boolean rootLayoutIncluded: boolean
firstItem?: boolean firstItem?: boolean
}): Promise<{ Component: React.ComponentType }> => { }): Promise<{ Component: React.ComponentType }> => {
const layoutOrPagePath = layout?.[1] || page?.[1] const layoutOrPagePath = layout?.[1] || page?.[1]
...@@ -1500,6 +1500,7 @@ export async function renderToHTMLOrFlight( ...@@ -1500,6 +1500,7 @@ export async function renderToHTMLOrFlight(
flightRouterState, flightRouterState,
parentRendered, parentRendered,
rscPayloadHead, rscPayloadHead,
rootLayoutIncluded,
}: { }: {
createSegmentPath: CreateSegmentPath createSegmentPath: CreateSegmentPath
loaderTreeToFilter: LoaderTree loaderTreeToFilter: LoaderTree
...@@ -1508,10 +1509,22 @@ export async function renderToHTMLOrFlight( ...@@ -1508,10 +1509,22 @@ export async function renderToHTMLOrFlight(
flightRouterState?: FlightRouterState flightRouterState?: FlightRouterState
parentRendered?: boolean parentRendered?: boolean
rscPayloadHead: React.ReactNode rscPayloadHead: React.ReactNode
rootLayoutIncluded: boolean
}): Promise<FlightDataPath> => { }): Promise<FlightDataPath> => {
const [segment, parallelRoutes] = loaderTreeToFilter const [segment, parallelRoutes, { layout }] = loaderTreeToFilter
const isLayout = typeof layout !== 'undefined'
const parallelRoutesKeys = Object.keys(parallelRoutes) 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 // 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 segmentParam = getDynamicParamFromSegment(segment)
const currentParams = const currentParams =
...@@ -1559,6 +1572,8 @@ export async function renderToHTMLOrFlight( ...@@ -1559,6 +1572,8 @@ export async function renderToHTMLOrFlight(
loaderTree: loaderTreeToFilter, loaderTree: loaderTreeToFilter,
parentParams: currentParams, parentParams: currentParams,
firstItem: isFirst, 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 /> return <Component />
...@@ -1588,6 +1603,7 @@ export async function renderToHTMLOrFlight( ...@@ -1588,6 +1603,7 @@ export async function renderToHTMLOrFlight(
parentRendered: parentRendered || renderComponentsOnThisLevel, parentRendered: parentRendered || renderComponentsOnThisLevel,
isFirst: false, isFirst: false,
rscPayloadHead, rscPayloadHead,
rootLayoutIncluded: rootLayoutIncludedAtThisLevelOrAbove,
}) })
if (typeof path[path.length - 1] !== 'string') { if (typeof path[path.length - 1] !== 'string') {
...@@ -1610,6 +1626,7 @@ export async function renderToHTMLOrFlight( ...@@ -1610,6 +1626,7 @@ export async function renderToHTMLOrFlight(
flightRouterState: providedFlightRouterState, flightRouterState: providedFlightRouterState,
isFirst: true, isFirst: true,
rscPayloadHead, rscPayloadHead,
rootLayoutIncluded: false,
}) })
).slice(1), ).slice(1),
] ]
...@@ -1688,6 +1705,7 @@ export async function renderToHTMLOrFlight( ...@@ -1688,6 +1705,7 @@ export async function renderToHTMLOrFlight(
loaderTree: loaderTree, loaderTree: loaderTree,
parentParams: {}, parentParams: {},
firstItem: true, firstItem: true,
rootLayoutIncluded: false,
}) })
const initialTree = createFlightRouterStateFromLoaderTree(loaderTree) 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