diff --git a/contributors.yml b/contributors.yml index c26071ff19..2ea23189d2 100644 --- a/contributors.yml +++ b/contributors.yml @@ -71,6 +71,7 @@ - david-bezero - david-crespo - dcblair +- dchenk - decadentsavant - dgrijuela - DigitalNaut diff --git a/packages/react-router/__tests__/router/lazy-discovery-test.ts b/packages/react-router/__tests__/router/lazy-discovery-test.ts index 13b84c3793..7483e82089 100644 --- a/packages/react-router/__tests__/router/lazy-discovery-test.ts +++ b/packages/react-router/__tests__/router/lazy-discovery-test.ts @@ -2103,6 +2103,81 @@ describe("Lazy Route Discovery (Fog of War)", () => { expect(router.state.matches.map((m) => m.route.id)).toEqual(["a", "b"]); }); + it("handles errors thrown from patchRoutesOnNavigation() when there are no partial matches (GET navigation)", async () => { + router = createRouter({ + history: createMemoryHistory(), + routes: [ + { + id: "a", + path: "a", + }, + ], + async patchRoutesOnNavigation({ patch }) { + await tick(); + throw new Error("broke!"); + patch("b", [ + { + id: "b", + path: "b", + loader() { + return "B"; + }, + }, + ]); + }, + }); + + await router.navigate("/b"); + expect(router.state).toMatchObject({ + matches: [], + location: { pathname: "/b" }, + actionData: null, + loaderData: {}, + errors: { + a: new Error("broke!"), + }, + }); + }); + + it("handles errors thrown from patchRoutesOnNavigation() when there are no partial matches (POST navigation)", async () => { + router = createRouter({ + history: createMemoryHistory(), + routes: [ + { + id: "a", + path: "a", + }, + ], + async patchRoutesOnNavigation({ patch }) { + await tick(); + throw new Error("broke!"); + patch("b", [ + { + id: "b", + path: "b", + action() { + return "B"; + }, + }, + ]); + }, + }); + + await router.navigate("/b", { + formMethod: "POST", + formData: createFormData({}), + }); + expect(router.state).toMatchObject({ + matches: [], + location: { pathname: "/b" }, + actionData: null, + loaderData: {}, + errors: { + a: new Error("broke!"), + }, + }); + }); + it("bubbles errors thrown from patchRoutesOnNavigation() during hydration", async () => { router = createRouter({ history: createMemoryHistory({