Skip to content

Commit bd37261

Browse files
committed
PR feedback
1 parent 3c4bd04 commit bd37261

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

packages/react-router/index.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,11 @@ export {
209209
};
210210

211211
function enhanceAgnosticRoute(route: RouteObject) {
212-
let updates: Partial<RouteObject> = {};
212+
let updates: Partial<RouteObject> & { hasErrorBoundary: boolean } = {
213+
// Note: this check also occurs in createRoutesFromChildren so update
214+
// there if you change this -- please and thank you!
215+
hasErrorBoundary: route.ErrorBoundary != null || route.errorElement != null,
216+
};
213217

214218
if (route.Component) {
215219
if (__DEV__) {
@@ -243,12 +247,6 @@ function enhanceAgnosticRoute(route: RouteObject) {
243247
});
244248
}
245249

246-
// Note: this check also occurs in createRoutesFromChildren so update
247-
// there if you change this -- please and thank you!
248-
if (route.ErrorBoundary || route.errorElement) {
249-
updates.hasErrorBoundary = true;
250-
}
251-
252250
return updates;
253251
}
254252

packages/react-router/lib/hooks.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -637,21 +637,17 @@ export function _renderMatches(
637637
// Only data routers handle errors
638638
let errorElement: React.ReactNode | null = null;
639639
if (dataRouterState) {
640-
if (match.route.ErrorBoundary) {
641-
errorElement = <match.route.ErrorBoundary />;
642-
} else {
643-
errorElement = match.route.errorElement || defaultErrorElement;
644-
}
640+
errorElement = match.route.errorElement || defaultErrorElement;
645641
}
646642
let matches = parentMatches.concat(renderedMatches.slice(0, index + 1));
647643
let getChildren = () => {
648-
let children: React.ReactNode = outlet;
644+
let children: React.ReactNode;
649645
if (error) {
650646
children = errorElement;
651-
} else if (match.route.Component) {
652-
children = <match.route.Component />;
653647
} else if (match.route.element) {
654648
children = match.route.element;
649+
} else {
650+
children = outlet;
655651
}
656652
return (
657653
<RenderedRoute

packages/router/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ export interface DetectErrorBoundaryFunction {
181181
* properties from framework-agnostic properties
182182
*/
183183
export interface EnhanceAgnosticRouteFunction {
184-
(route: AgnosticRouteObject): Record<string, any>;
184+
(route: AgnosticRouteObject): {
185+
hasErrorBoundary: boolean;
186+
} & Record<string, any>;
185187
}
186188

187189
/**

0 commit comments

Comments
 (0)