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
75a9dfac
Unverified
Commit
75a9dfac
authored
Dec 23, 2024
by
Jiachi Liu
Committed by
GitHub
Dec 23, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: error boundary rendering in app-render (#74259)
parent
e93f27e3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
63 deletions
+75
-63
create-component-tree.tsx
...ages/next/src/server/app-render/create-component-tree.tsx
+75
-63
No files found.
packages/next/src/server/app-render/create-component-tree.tsx
View file @
75a9dfac
...
@@ -209,12 +209,6 @@ async function createComponentTreeInternal({
...
@@ -209,12 +209,6 @@ async function createComponentTreeInternal({
injectedJS
:
injectedJSWithCurrentLayout
,
injectedJS
:
injectedJSWithCurrentLayout
,
})
})
:
[]
:
[]
const
forbiddenElement
=
Forbidden
?
(
<>
{
forbiddenStyles
}
<
Forbidden
/>
</>
)
:
undefined
const
[
Unauthorized
,
unauthorizedStyles
]
=
const
[
Unauthorized
,
unauthorizedStyles
]
=
authInterrupts
&&
unauthorized
authInterrupts
&&
unauthorized
...
@@ -226,6 +220,21 @@ async function createComponentTreeInternal({
...
@@ -226,6 +220,21 @@ async function createComponentTreeInternal({
injectedJS
:
injectedJSWithCurrentLayout
,
injectedJS
:
injectedJSWithCurrentLayout
,
})
})
:
[]
:
[]
const
notFoundElement
=
NotFound
?
(
<>
{
notFoundStyles
}
<
NotFound
/>
</>
)
:
undefined
const
forbiddenElement
=
Forbidden
?
(
<>
{
forbiddenStyles
}
<
Forbidden
/>
</>
)
:
undefined
const
unauthorizedElement
=
Unauthorized
?
(
const
unauthorizedElement
=
Unauthorized
?
(
<>
<>
{
unauthorizedStyles
}
{
unauthorizedStyles
}
...
@@ -411,13 +420,9 @@ async function createComponentTreeInternal({
...
@@ -411,13 +420,9 @@ async function createComponentTreeInternal({
const
isChildrenRouteKey
=
parallelRouteKey
===
'children'
const
isChildrenRouteKey
=
parallelRouteKey
===
'children'
const
parallelRoute
=
parallelRoutes
[
parallelRouteKey
]
const
parallelRoute
=
parallelRoutes
[
parallelRouteKey
]
const
notFoundComponent
=
const
notFoundComponent
=
isChildrenRouteKey
NotFound
&&
isChildrenRouteKey
?
(
?
notFoundElement
<>
:
undefined
{
notFoundStyles
}
<
NotFound
/>
</>
)
:
undefined
const
forbiddenComponent
=
isChildrenRouteKey
const
forbiddenComponent
=
isChildrenRouteKey
?
forbiddenElement
?
forbiddenElement
...
@@ -709,56 +714,30 @@ async function createComponentTreeInternal({
...
@@ -709,56 +714,30 @@ async function createComponentTreeInternal({
// 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.
if
(
NotFound
)
{
notfoundClientSegment
=
createErrorBoundaryClientSegmentRoot
({
const
notFoundParallelRouteProps
=
{
ErrorBoundaryComponent
:
NotFound
,
children
:
(
errorElement
:
notFoundElement
,
<>
ClientSegmentRoot
,
{
notFoundStyles
}
layerAssets
,
<
NotFound
/>
SegmentComponent
,
</>
currentParams
,
),
})
}
forbiddenClientSegment
=
createErrorBoundaryClientSegmentRoot
({
notfoundClientSegment
=
(
ErrorBoundaryComponent
:
Forbidden
,
<>
errorElement
:
forbiddenElement
,
{
layerAssets
}
ClientSegmentRoot
,
<
ClientSegmentRoot
layerAssets
,
Component=
{
SegmentComponent
}
SegmentComponent
,
slots=
{
notFoundParallelRouteProps
}
currentParams
,
params=
{
currentParams
}
})
/>
unauthorizedClientSegment
=
createErrorBoundaryClientSegmentRoot
({
</>
ErrorBoundaryComponent
:
Unauthorized
,
)
errorElement
:
unauthorizedElement
,
}
ClientSegmentRoot
,
if
(
Forbidden
)
{
layerAssets
,
const
forbiddenParallelRouteProps
=
{
SegmentComponent
,
children
:
forbiddenElement
,
currentParams
,
}
})
forbiddenClientSegment
=
(
<>
{
layerAssets
}
<
ClientSegmentRoot
Component=
{
SegmentComponent
}
slots=
{
forbiddenParallelRouteProps
}
params=
{
currentParams
}
/>
</>
)
}
if
(
Unauthorized
)
{
const
unauthorizedParallelRouteProps
=
{
children
:
unauthorizedElement
,
}
unauthorizedClientSegment
=
(
<>
{
layerAssets
}
<
ClientSegmentRoot
Component=
{
SegmentComponent
}
slots=
{
unauthorizedParallelRouteProps
}
params=
{
currentParams
}
/>
</>
)
}
if
(
if
(
notfoundClientSegment
||
notfoundClientSegment
||
forbiddenClientSegment
||
forbiddenClientSegment
||
...
@@ -861,3 +840,36 @@ async function MetadataOutlet({
...
@@ -861,3 +840,36 @@ async function MetadataOutlet({
return
null
return
null
}
}
MetadataOutlet
.
displayName
=
OUTLET_BOUNDARY_NAME
MetadataOutlet
.
displayName
=
OUTLET_BOUNDARY_NAME
function
createErrorBoundaryClientSegmentRoot
({
ErrorBoundaryComponent
,
errorElement
,
ClientSegmentRoot
,
layerAssets
,
SegmentComponent
,
currentParams
,
}:
{
ErrorBoundaryComponent
:
React
.
ComponentType
<
any
>
|
undefined
errorElement
:
React
.
ReactNode
ClientSegmentRoot
:
React
.
ComponentType
<
any
>
layerAssets
:
React
.
ReactNode
SegmentComponent
:
React
.
ComponentType
<
any
>
currentParams
:
Params
})
{
if
(
ErrorBoundaryComponent
)
{
const
notFoundParallelRouteProps
=
{
children
:
errorElement
,
}
return
(
<>
{
layerAssets
}
<
ClientSegmentRoot
Component=
{
SegmentComponent
}
slots=
{
notFoundParallelRouteProps
}
params=
{
currentParams
}
/>
</>
)
}
return
null
}
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