Skip to content

Commit a88612b

Browse files
committed
Updates
1 parent 0df9b38 commit a88612b

File tree

2 files changed

+57
-5
lines changed

2 files changed

+57
-5
lines changed

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,7 +2120,21 @@ describe("Lazy Route Discovery (Fog of War)", () => {
21202120

21212121
await router.navigate("/b");
21222122
expect(router.state).toMatchObject({
2123-
matches: [],
2123+
// A bit odd but this is a result of our best attempt to display some form
2124+
// of error UI to the user - follows the same logic we use on 404s
2125+
matches: [
2126+
{
2127+
params: {},
2128+
pathname: "",
2129+
pathnameBase: "",
2130+
route: {
2131+
children: undefined,
2132+
hasErrorBoundary: false,
2133+
id: "a",
2134+
path: "a",
2135+
},
2136+
},
2137+
],
21242138
location: { pathname: "/b" },
21252139
actionData: null,
21262140
loaderData: {},
@@ -2150,7 +2164,21 @@ describe("Lazy Route Discovery (Fog of War)", () => {
21502164
formData: createFormData({}),
21512165
});
21522166
expect(router.state).toMatchObject({
2153-
matches: [],
2167+
// A bit odd but this is a result of our best attempt to display some form
2168+
// of error UI to the user - follows the same logic we use on 404s
2169+
matches: [
2170+
{
2171+
params: {},
2172+
pathname: "",
2173+
pathnameBase: "",
2174+
route: {
2175+
children: undefined,
2176+
hasErrorBoundary: false,
2177+
id: "a",
2178+
path: "a",
2179+
},
2180+
},
2181+
],
21542182
location: { pathname: "/b" },
21552183
actionData: null,
21562184
loaderData: {},

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,9 +1802,22 @@ export function createRouter(init: RouterInit): Router {
18021802
if (discoverResult.type === "aborted") {
18031803
return { shortCircuited: true };
18041804
} else if (discoverResult.type === "error") {
1805-
let boundaryId =
1806-
findNearestBoundary(discoverResult.partialMatches)?.route.id ??
1807-
getShortCircuitMatches(dataRoutes).route.id;
1805+
if (discoverResult.partialMatches.length === 0) {
1806+
let { matches, route } = getShortCircuitMatches(dataRoutes);
1807+
return {
1808+
matches,
1809+
pendingActionResult: [
1810+
route.id,
1811+
{
1812+
type: ResultType.error,
1813+
error: discoverResult.error,
1814+
},
1815+
],
1816+
};
1817+
}
1818+
1819+
let boundaryId = findNearestBoundary(discoverResult.partialMatches)
1820+
?.route.id;
18081821
return {
18091822
matches: discoverResult.partialMatches,
18101823
pendingActionResult: [
@@ -1997,6 +2010,17 @@ export function createRouter(init: RouterInit): Router {
19972010
if (discoverResult.type === "aborted") {
19982011
return { shortCircuited: true };
19992012
} else if (discoverResult.type === "error") {
2013+
if (discoverResult.partialMatches.length === 0) {
2014+
let { matches, route } = getShortCircuitMatches(dataRoutes);
2015+
return {
2016+
matches,
2017+
loaderData: {},
2018+
errors: {
2019+
[route.id]: discoverResult.error,
2020+
},
2021+
};
2022+
}
2023+
20002024
let boundaryId =
20012025
findNearestBoundary(discoverResult.partialMatches)?.route.id ??
20022026
getShortCircuitMatches(dataRoutes).route.id;

0 commit comments

Comments
 (0)