Skip to content

Commit 3fdce65

Browse files
Fix RSC outlet fallback warnings on error (#14021)
1 parent 3bce6f0 commit 3fdce65

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

.changeset/proud-dingos-nail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-router": patch
3+
---
4+
5+
In RSC Data Mode, fix `Matched leaf route at location "/..." does not have an element or Component` warnings when error boundaries are rendered.

packages/react-router/lib/rsc/server.rsc.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import type { RouteMatch, RouteObject } from "../context";
4040
import invariant from "../server-runtime/invariant";
4141

4242
import {
43+
Outlet as UNTYPED_Outlet,
4344
UNSAFE_WithComponentProps,
4445
UNSAFE_WithHydrateFallbackProps,
4546
UNSAFE_WithErrorBoundaryProps,
@@ -48,13 +49,15 @@ import {
4849
// TSConfig, it breaks the Parcel build within this repo.
4950
} from "react-router/internal/react-server-client";
5051
import type {
52+
Outlet as OutletType,
5153
WithComponentProps as WithComponentPropsType,
5254
WithErrorBoundaryProps as WithErrorBoundaryPropsType,
5355
WithHydrateFallbackProps as WithHydrateFallbackPropsType,
5456
RouteComponentProps,
5557
ErrorBoundaryProps,
5658
HydrateFallbackProps,
5759
} from "../components";
60+
const Outlet: typeof OutletType = UNTYPED_Outlet;
5861
const WithComponentProps: typeof WithComponentPropsType =
5962
UNSAFE_WithComponentProps;
6063
const WithErrorBoundaryProps: typeof WithErrorBoundaryPropsType =
@@ -1016,8 +1019,9 @@ async function getRSCRouteMatch(
10161019
const actionData = staticContext.actionData?.[match.route.id];
10171020
const params = match.params;
10181021
// TODO: DRY this up once it's fully fleshed out
1019-
const element =
1020-
Component && shouldRenderComponent
1022+
let element: React.ReactElement | undefined = undefined;
1023+
if (Component) {
1024+
element = shouldRenderComponent
10211025
? React.createElement(
10221026
Layout,
10231027
null,
@@ -1034,8 +1038,8 @@ async function getRSCRouteMatch(
10341038
),
10351039
} satisfies RouteComponentProps),
10361040
)
1037-
: // TODO: Render outlet instead?
1038-
undefined;
1041+
: React.createElement(Outlet);
1042+
}
10391043
let error: unknown = undefined;
10401044

10411045
if (ErrorBoundary && staticContext.errors) {

0 commit comments

Comments
 (0)