@@ -984,22 +984,15 @@ async function getRenderPayload(
984
984
985
985
let matchesPromise = Promise . all (
986
986
staticContext . matches . map ( ( match , i ) => {
987
- // Only bother rendering Server Components for routes that we're surfacing,
988
- // so nothing at/below an error boundary and prune routes if included in
989
- // `routeIdsToLoad`. This is specifically important when a middleware
990
- // or loader throws and we don't have any `loaderData` to pass through as
991
- // props leading to render-time errors of the server component
992
- let shouldRenderComponent =
993
- i <= deepestRenderedRouteIdx &&
994
- ( ! routeIdsToLoad || routeIdsToLoad . includes ( match . route . id ) ) &&
995
- ( ! staticContext . errors || ! ( match . route . id in staticContext . errors ) ) ;
996
-
997
- return getRSCRouteMatch (
987
+ let isBelowErrorBoundary = i > deepestRenderedRouteIdx ;
988
+ let parentId = parentIds [ match . route . id ] ;
989
+ return getRSCRouteMatch ( {
998
990
staticContext,
999
991
match,
1000
- shouldRenderComponent ,
1001
- parentIds [ match . route . id ] ,
1002
- ) ;
992
+ routeIdsToLoad,
993
+ isBelowErrorBoundary,
994
+ parentId,
995
+ } ) ;
1003
996
} ) ,
1004
997
) ;
1005
998
@@ -1019,12 +1012,19 @@ async function getRenderPayload(
1019
1012
} ;
1020
1013
}
1021
1014
1022
- async function getRSCRouteMatch (
1023
- staticContext : StaticHandlerContext ,
1024
- match : AgnosticDataRouteMatch ,
1025
- shouldRenderComponent : boolean ,
1026
- parentId : string | undefined ,
1027
- ) {
1015
+ async function getRSCRouteMatch ( {
1016
+ staticContext,
1017
+ match,
1018
+ isBelowErrorBoundary,
1019
+ routeIdsToLoad,
1020
+ parentId,
1021
+ } : {
1022
+ staticContext : StaticHandlerContext ;
1023
+ match : AgnosticDataRouteMatch ;
1024
+ isBelowErrorBoundary : boolean ;
1025
+ routeIdsToLoad : string [ ] | null ;
1026
+ parentId : string | undefined ;
1027
+ } ) {
1028
1028
// @ts -expect-error - FIXME: Fix the types here
1029
1029
await explodeLazyRoute ( match . route ) ;
1030
1030
const Layout = ( match . route as any ) . Layout || React . Fragment ;
@@ -1036,8 +1036,15 @@ async function getRSCRouteMatch(
1036
1036
const params = match . params ;
1037
1037
// TODO: DRY this up once it's fully fleshed out
1038
1038
let element : React . ReactElement | undefined = undefined ;
1039
- if ( Component ) {
1040
- element = shouldRenderComponent
1039
+ let shouldLoadRoute =
1040
+ ! routeIdsToLoad || routeIdsToLoad . includes ( match . route . id ) ;
1041
+ // Only bother rendering Server Components for routes that we're surfacing,
1042
+ // so nothing at/below an error boundary and prune routes if included in
1043
+ // `routeIdsToLoad`. This is specifically important when a middleware
1044
+ // or loader throws and we don't have any `loaderData` to pass through as
1045
+ // props leading to render-time errors of the server component
1046
+ if ( Component && shouldLoadRoute ) {
1047
+ element = ! isBelowErrorBoundary
1041
1048
? React . createElement (
1042
1049
Layout ,
1043
1050
null ,
0 commit comments