Commit 5c0efcd7 authored by Tim Neutkens's avatar Tim Neutkens

renderLayoutComponent

parent 25c255ca
...@@ -123,10 +123,6 @@ async function createComponentTreeInternal( ...@@ -123,10 +123,6 @@ async function createComponentTreeInternal(
createElement, createElement,
Fragment, Fragment,
SegmentViewNode, SegmentViewNode,
HTTPAccessFallbackBoundary,
ClientSegmentRoot,
createServerParamsForServerSegment,
createPrerenderParamsForClientSegment,
serverHooks: { DynamicServerError }, serverHooks: { DynamicServerError },
Postpone, Postpone,
}, },
...@@ -561,18 +557,80 @@ async function createComponentTreeInternal( ...@@ -561,18 +557,80 @@ async function createComponentTreeInternal(
isPossiblyPartialResponse isPossiblyPartialResponse
) )
} else { } else {
const SegmentComponent = Component return renderLayoutComponent(
const isRootLayoutWithChildrenSlotAndAtLeastOneMoreSlot = ctx,
Component,
isClientComponent,
rootLayoutAtThisLevel && rootLayoutAtThisLevel &&
'children' in parallelRoutes && 'children' in parallelRoutes &&
Object.keys(parallelRoutes).length > 1 Object.keys(parallelRoutes).length > 1,
currentParams,
parallelRouteProps,
optionalCatchAllParamName,
varyParamsAccumulator,
isRuntimePrefetchable,
NotFound,
Forbidden,
Unauthorized,
notFoundElement,
forbiddenElement,
unauthorizedElement,
notFoundStyles,
layerAssets,
tree,
dir,
isSegmentViewEnabled,
parallelRouteCacheNodeSeedData,
loadingData,
isPossiblyPartialResponse
)
}
}
function renderLayoutComponent(
ctx: AppRenderContext,
SegmentComponent: ComponentType<any>,
isClientComponent: boolean,
isRootLayoutWithChildrenSlotAndAtLeastOneMoreSlot: boolean,
currentParams: Params,
parallelRouteProps: { [key: string]: React.ReactNode },
optionalCatchAllParamName: string | null,
varyParamsAccumulator: VaryParamsAccumulator | null,
isRuntimePrefetchable: boolean,
NotFound: ComponentType<any> | undefined,
Forbidden: ComponentType<any> | undefined,
Unauthorized: ComponentType<any> | undefined,
notFoundElement: React.ReactNode | undefined,
forbiddenElement: React.ReactNode | undefined,
unauthorizedElement: React.ReactNode | undefined,
notFoundStyles: React.ReactNode | undefined,
layerAssets: React.ReactNode,
tree: LoaderTree,
dir: string,
isSegmentViewEnabled: boolean,
parallelRouteCacheNodeSeedData: Record<string, CacheNodeSeedData | null>,
loadingData: LoadingModuleData,
isPossiblyPartialResponse: boolean
): CacheNodeSeedData {
const {
renderOpts: { cacheComponents },
workStore: { isStaticGeneration },
componentMod: {
createElement,
Fragment,
SegmentViewNode,
HTTPAccessFallbackBoundary,
ClientSegmentRoot,
createServerParamsForServerSegment,
createPrerenderParamsForClientSegment,
},
} = ctx
let segmentNode: React.ReactNode let segmentNode: React.ReactNode
if (isClientComponent) { if (isClientComponent) {
let clientSegment: React.ReactNode let clientSegment: React.ReactNode
if (cacheComponents) { if (cacheComponents) {
// Params are omitted when Cache Components is enabled
clientSegment = createElement(ClientSegmentRoot, { clientSegment = createElement(ClientSegmentRoot, {
Component: SegmentComponent, Component: SegmentComponent,
slots: parallelRouteProps, slots: parallelRouteProps,
...@@ -602,15 +660,12 @@ async function createComponentTreeInternal( ...@@ -602,15 +660,12 @@ async function createComponentTreeInternal(
} }
if (isRootLayoutWithChildrenSlotAndAtLeastOneMoreSlot) { if (isRootLayoutWithChildrenSlotAndAtLeastOneMoreSlot) {
let notfoundClientSegment: React.ReactNode
let forbiddenClientSegment: React.ReactNode
let unauthorizedClientSegment: React.ReactNode
// TODO-APP: This is a hack to support unmatched parallel routes, which will throw `notFound()`. // TODO-APP: This is a hack to support unmatched parallel routes, which will throw `notFound()`.
// This ensures that a `HTTPAccessFallbackBoundary` is available for when that happens, // This ensures that a `HTTPAccessFallbackBoundary` is available for when that happens,
// but it's not ideal, as it needlessly invokes the `NotFound` component and renders the `RootLayout` twice. // but it's not ideal, as it needlessly invokes the `NotFound` component and renders the `RootLayout` twice.
// We should instead look into handling the fallback behavior differently in development mode so that it doesn't // We should instead look into handling the fallback behavior differently in development mode so that it doesn't
// rely on the `NotFound` behavior. // rely on the `NotFound` behavior.
notfoundClientSegment = createErrorBoundaryClientSegmentRoot({ const notfoundClientSegment = createErrorBoundaryClientSegmentRoot({
ctx, ctx,
ErrorBoundaryComponent: NotFound, ErrorBoundaryComponent: NotFound,
errorElement: notFoundElement, errorElement: notFoundElement,
...@@ -619,7 +674,7 @@ async function createComponentTreeInternal( ...@@ -619,7 +674,7 @@ async function createComponentTreeInternal(
SegmentComponent, SegmentComponent,
currentParams, currentParams,
}) })
forbiddenClientSegment = createErrorBoundaryClientSegmentRoot({ const forbiddenClientSegment = createErrorBoundaryClientSegmentRoot({
ctx, ctx,
ErrorBoundaryComponent: Forbidden, ErrorBoundaryComponent: Forbidden,
errorElement: forbiddenElement, errorElement: forbiddenElement,
...@@ -628,7 +683,7 @@ async function createComponentTreeInternal( ...@@ -628,7 +683,7 @@ async function createComponentTreeInternal(
SegmentComponent, SegmentComponent,
currentParams, currentParams,
}) })
unauthorizedClientSegment = createErrorBoundaryClientSegmentRoot({ const unauthorizedClientSegment = createErrorBoundaryClientSegmentRoot({
ctx, ctx,
ErrorBoundaryComponent: Unauthorized, ErrorBoundaryComponent: Unauthorized,
errorElement: unauthorizedElement, errorElement: unauthorizedElement,
...@@ -766,7 +821,6 @@ async function createComponentTreeInternal( ...@@ -766,7 +821,6 @@ async function createComponentTreeInternal(
) )
: segmentNode : segmentNode
// For layouts we just render the component
return createSeedData( return createSeedData(
ctx, ctx,
wrappedSegmentNode, wrappedSegmentNode,
...@@ -777,7 +831,6 @@ async function createComponentTreeInternal( ...@@ -777,7 +831,6 @@ async function createComponentTreeInternal(
varyParamsAccumulator varyParamsAccumulator
) )
}
} }
function renderPageComponent( function renderPageComponent(
......
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