Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
5c0efcd7
Commit
5c0efcd7
authored
Mar 09, 2026
by
Tim Neutkens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renderLayoutComponent
parent
25c255ca
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
248 additions
and
195 deletions
+248
-195
create-component-tree.tsx
...ages/next/src/server/app-render/create-component-tree.tsx
+248
-195
No files found.
packages/next/src/server/app-render/create-component-tree.tsx
View file @
5c0efcd7
...
...
@@ -123,10 +123,6 @@ async function createComponentTreeInternal(
createElement
,
Fragment
,
SegmentViewNode
,
HTTPAccessFallbackBoundary
,
ClientSegmentRoot
,
createServerParamsForServerSegment
,
createPrerenderParamsForClientSegment
,
serverHooks
:
{
DynamicServerError
},
Postpone
,
},
...
...
@@ -561,184 +557,156 @@ async function createComponentTreeInternal(
isPossiblyPartialResponse
)
}
else
{
const
SegmentComponent
=
Component
const
isRootLayoutWithChildrenSlotAndAtLeastOneMoreSlot
=
return
renderLayoutComponent
(
ctx
,
Component
,
isClientComponent
,
rootLayoutAtThisLevel
&&
'children'
in
parallelRoutes
&&
Object
.
keys
(
parallelRoutes
).
length
>
1
let
segmentNode
:
React
.
ReactNode
if
(
isClientComponent
)
{
let
clientSegment
:
React
.
ReactNode
if
(
cacheComponents
)
{
// Params are omitted when Cache Components is enabled
clientSegment
=
createElement
(
ClientSegmentRoot
,
{
Component
:
SegmentComponent
,
slots
:
parallelRouteProps
,
serverProvidedParams
:
null
,
})
}
else
if
(
isStaticGeneration
)
{
const
promiseOfParams
=
createPrerenderParamsForClientSegment
(
currentParams
)
clientSegment
=
createElement
(
ClientSegmentRoot
,
{
Component
:
SegmentComponent
,
slots
:
parallelRouteProps
,
serverProvidedParams
:
{
params
:
currentParams
,
promises
:
[
promiseOfParams
],
},
})
}
else
{
clientSegment
=
createElement
(
ClientSegmentRoot
,
{
Component
:
SegmentComponent
,
slots
:
parallelRouteProps
,
serverProvidedParams
:
{
params
:
currentParams
,
promises
:
null
,
},
})
}
'children'
in
parallelRoutes
&&
Object
.
keys
(
parallelRoutes
).
length
>
1
,
currentParams
,
parallelRouteProps
,
optionalCatchAllParamName
,
varyParamsAccumulator
,
isRuntimePrefetchable
,
NotFound
,
Forbidden
,
Unauthorized
,
notFoundElement
,
forbiddenElement
,
unauthorizedElement
,
notFoundStyles
,
layerAssets
,
tree
,
dir
,
isSegmentViewEnabled
,
parallelRouteCacheNodeSeedData
,
loadingData
,
isPossiblyPartialResponse
)
}
}
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()`.
// 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.
// We should instead look into handling the fallback behavior differently in development mode so that it doesn't
// rely on the `NotFound` behavior.
notfoundClientSegment
=
createErrorBoundaryClientSegmentRoot
({
ctx
,
ErrorBoundaryComponent
:
NotFound
,
errorElement
:
notFoundElement
,
ClientSegmentRoot
,
layerAssets
,
SegmentComponent
,
currentParams
,
})
forbiddenClientSegment
=
createErrorBoundaryClientSegmentRoot
({
ctx
,
ErrorBoundaryComponent
:
Forbidden
,
errorElement
:
forbiddenElement
,
ClientSegmentRoot
,
layerAssets
,
SegmentComponent
,
currentParams
,
})
unauthorizedClientSegment
=
createErrorBoundaryClientSegmentRoot
({
ctx
,
ErrorBoundaryComponent
:
Unauthorized
,
errorElement
:
unauthorizedElement
,
ClientSegmentRoot
,
layerAssets
,
SegmentComponent
,
currentParams
,
})
if
(
notfoundClientSegment
||
forbiddenClientSegment
||
unauthorizedClientSegment
)
{
segmentNode
=
createElement
(
HTTPAccessFallbackBoundary
,
{
key
:
cacheNodeKey
,
notFound
:
notfoundClientSegment
,
forbidden
:
forbiddenClientSegment
,
unauthorized
:
unauthorizedClientSegment
,
},
layerAssets
,
clientSegment
)
}
else
{
segmentNode
=
createElement
(
Fragment
,
{
key
:
cacheNodeKey
,
},
layerAssets
,
clientSegment
)
}
}
else
{
segmentNode
=
createElement
(
Fragment
,
{
key
:
cacheNodeKey
,
},
layerAssets
,
clientSegment
)
}
}
else
{
const
params
=
createServerParamsForServerSegment
(
currentParams
,
optionalCatchAllParamName
,
varyParamsAccumulator
,
isRuntimePrefetchable
)
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
serverSegment
:
React
.
ReactNode
let
segmentNode
:
React
.
ReactNode
if
(
isUseCacheFunction
(
SegmentComponent
))
{
const
UseCacheLayoutComponent
:
ComponentType
<
UseCacheLayoutProps
>
=
SegmentComponent
if
(
isClientComponent
)
{
let
clientSegment
:
React
.
ReactNode
if
(
cacheComponents
)
{
clientSegment
=
createElement
(
ClientSegmentRoot
,
{
Component
:
SegmentComponent
,
slots
:
parallelRouteProps
,
serverProvidedParams
:
null
,
})
}
else
if
(
isStaticGeneration
)
{
const
promiseOfParams
=
createPrerenderParamsForClientSegment
(
currentParams
)
serverSegment
=
createElement
(
UseCacheLayoutComponent
,
{
...
parallelRouteProps
,
params
:
params
,
$
$isLayout
:
true
,
},
// Force static children here so that they're validated.
// See https://github.com/facebook/react/pull/34846
parallelRouteProps
.
children
)
}
else
{
serverSegment
=
createElement
(
SegmentComponent
,
{
...
parallelRouteProps
,
params
:
params
,
},
// Force static children here so that they're validated.
// See https://github.com/facebook/react/pull/34846
parallelRouteProps
.
children
)
}
clientSegment
=
createElement
(
ClientSegmentRoot
,
{
Component
:
SegmentComponent
,
slots
:
parallelRouteProps
,
serverProvidedParams
:
{
params
:
currentParams
,
promises
:
[
promiseOfParams
],
},
})
}
else
{
clientSegment
=
createElement
(
ClientSegmentRoot
,
{
Component
:
SegmentComponent
,
slots
:
parallelRouteProps
,
serverProvidedParams
:
{
params
:
currentParams
,
promises
:
null
,
},
})
}
if
(
isRootLayoutWithChildrenSlotAndAtLeastOneMoreSlot
)
{
// 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,
// 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
// rely on the `NotFound` behavior.
if
(
isRootLayoutWithChildrenSlotAndAtLeastOneMoreSlot
)
{
// 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,
// 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
// rely on the `NotFound` behavior.
const
notfoundClientSegment
=
createErrorBoundaryClientSegmentRoot
({
ctx
,
ErrorBoundaryComponent
:
NotFound
,
errorElement
:
notFoundElement
,
ClientSegmentRoot
,
layerAssets
,
SegmentComponent
,
currentParams
,
})
const
forbiddenClientSegment
=
createErrorBoundaryClientSegmentRoot
({
ctx
,
ErrorBoundaryComponent
:
Forbidden
,
errorElement
:
forbiddenElement
,
ClientSegmentRoot
,
layerAssets
,
SegmentComponent
,
currentParams
,
})
const
unauthorizedClientSegment
=
createErrorBoundaryClientSegmentRoot
({
ctx
,
ErrorBoundaryComponent
:
Unauthorized
,
errorElement
:
unauthorizedElement
,
ClientSegmentRoot
,
layerAssets
,
SegmentComponent
,
currentParams
,
})
if
(
notfoundClientSegment
||
forbiddenClientSegment
||
unauthorizedClientSegment
)
{
segmentNode
=
createElement
(
HTTPAccessFallbackBoundary
,
{
key
:
cacheNodeKey
,
notFound
:
notFoundElement
?
createElement
(
Fragment
,
null
,
layerAssets
,
createElement
(
SegmentComponent
,
{
params
:
params
,
},
notFoundStyles
,
notFoundElement
)
)
:
undefined
,
notFound
:
notfoundClientSegment
,
forbidden
:
forbiddenClientSegment
,
unauthorized
:
unauthorizedClientSegment
,
},
layerAssets
,
server
Segment
client
Segment
)
}
else
{
segmentNode
=
createElement
(
...
...
@@ -747,37 +715,122 @@ async function createComponentTreeInternal(
key
:
cacheNodeKey
,
},
layerAssets
,
server
Segment
client
Segment
)
}
}
else
{
segmentNode
=
createElement
(
Fragment
,
{
key
:
cacheNodeKey
,
},
layerAssets
,
clientSegment
)
}
}
else
{
const
params
=
createServerParamsForServerSegment
(
currentParams
,
optionalCatchAllParamName
,
varyParamsAccumulator
,
isRuntimePrefetchable
)
const
layoutFilePath
=
getConventionPathByType
(
tree
,
dir
,
'layout'
)
const
wrappedSegmentNode
=
isSegmentViewEnabled
&&
layoutFilePath
?
createElement
(
SegmentViewNode
,
{
key
:
'layout'
,
type
:
'layout'
,
pagePath
:
layoutFilePath
,
},
segmentNode
)
:
segmentNode
// For layouts we just render the component
return
createSeedData
(
ctx
,
wrappedSegmentNode
,
parallelRouteCacheNodeSeedData
,
loadingData
,
isPossiblyPartialResponse
,
isRuntimePrefetchable
,
let
serverSegment
:
React
.
ReactNode
varyParamsAccumulator
)
if
(
isUseCacheFunction
(
SegmentComponent
))
{
const
UseCacheLayoutComponent
:
ComponentType
<
UseCacheLayoutProps
>
=
SegmentComponent
serverSegment
=
createElement
(
UseCacheLayoutComponent
,
{
...
parallelRouteProps
,
params
:
params
,
$
$isLayout
:
true
,
},
// Force static children here so that they're validated.
// See https://github.com/facebook/react/pull/34846
parallelRouteProps
.
children
)
}
else
{
serverSegment
=
createElement
(
SegmentComponent
,
{
...
parallelRouteProps
,
params
:
params
,
},
// Force static children here so that they're validated.
// See https://github.com/facebook/react/pull/34846
parallelRouteProps
.
children
)
}
if
(
isRootLayoutWithChildrenSlotAndAtLeastOneMoreSlot
)
{
// 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,
// 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
// rely on the `NotFound` behavior.
segmentNode
=
createElement
(
HTTPAccessFallbackBoundary
,
{
key
:
cacheNodeKey
,
notFound
:
notFoundElement
?
createElement
(
Fragment
,
null
,
layerAssets
,
createElement
(
SegmentComponent
,
{
params
:
params
,
},
notFoundStyles
,
notFoundElement
)
)
:
undefined
,
},
layerAssets
,
serverSegment
)
}
else
{
segmentNode
=
createElement
(
Fragment
,
{
key
:
cacheNodeKey
,
},
layerAssets
,
serverSegment
)
}
}
const
layoutFilePath
=
getConventionPathByType
(
tree
,
dir
,
'layout'
)
const
wrappedSegmentNode
=
isSegmentViewEnabled
&&
layoutFilePath
?
createElement
(
SegmentViewNode
,
{
key
:
'layout'
,
type
:
'layout'
,
pagePath
:
layoutFilePath
,
},
segmentNode
)
:
segmentNode
return
createSeedData
(
ctx
,
wrappedSegmentNode
,
parallelRouteCacheNodeSeedData
,
loadingData
,
isPossiblyPartialResponse
,
isRuntimePrefetchable
,
varyParamsAccumulator
)
}
function
renderPageComponent
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment