Skip to content

Commit 0df9b38

Browse files
committed
Fix
1 parent 992a3d2 commit 0df9b38

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

.changeset/real-rules-compare.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+
Fix `TypeError` if you throw from `patchRoutesOnNavigation` when no partial matches exist

packages/react-router/__tests__/router/lazy-discovery-test.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,15 +2115,6 @@ describe("Lazy Route Discovery (Fog of War)", () => {
21152115
async patchRoutesOnNavigation({ patch }) {
21162116
await tick();
21172117
throw new Error("broke!");
2118-
patch("b", [
2119-
{
2120-
id: "b",
2121-
path: "b",
2122-
loader() {
2123-
return "B";
2124-
},
2125-
},
2126-
]);
21272118
},
21282119
});
21292120

@@ -2151,15 +2142,6 @@ describe("Lazy Route Discovery (Fog of War)", () => {
21512142
async patchRoutesOnNavigation({ patch }) {
21522143
await tick();
21532144
throw new Error("broke!");
2154-
patch("b", [
2155-
{
2156-
id: "b",
2157-
path: "b",
2158-
action() {
2159-
return "B";
2160-
},
2161-
},
2162-
]);
21632145
},
21642146
});
21652147

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,8 +1802,9 @@ export function createRouter(init: RouterInit): Router {
18021802
if (discoverResult.type === "aborted") {
18031803
return { shortCircuited: true };
18041804
} else if (discoverResult.type === "error") {
1805-
let boundaryId = findNearestBoundary(discoverResult.partialMatches)
1806-
.route.id;
1805+
let boundaryId =
1806+
findNearestBoundary(discoverResult.partialMatches)?.route.id ??
1807+
getShortCircuitMatches(dataRoutes).route.id;
18071808
return {
18081809
matches: discoverResult.partialMatches,
18091810
pendingActionResult: [
@@ -1996,8 +1997,9 @@ export function createRouter(init: RouterInit): Router {
19961997
if (discoverResult.type === "aborted") {
19971998
return { shortCircuited: true };
19981999
} else if (discoverResult.type === "error") {
1999-
let boundaryId = findNearestBoundary(discoverResult.partialMatches)
2000-
.route.id;
2000+
let boundaryId =
2001+
findNearestBoundary(discoverResult.partialMatches)?.route.id ??
2002+
getShortCircuitMatches(dataRoutes).route.id;
20012003
return {
20022004
matches: discoverResult.partialMatches,
20032005
loaderData: {},

0 commit comments

Comments
 (0)