diff --git a/.changeset/hmr-error-boundary.md b/.changeset/hmr-error-boundary.md new file mode 100644 index 0000000000..b5d111361b --- /dev/null +++ b/.changeset/hmr-error-boundary.md @@ -0,0 +1,5 @@ +--- +"@remix-run/router": patch +--- + +Fix HMR-driven error boundaries by properly reconstructing new routes and `manifest` in `\_internalSetRoutes` diff --git a/packages/router/__tests__/router-test.ts b/packages/router/__tests__/router-test.ts index 7720c49408..fd8d108c80 100644 --- a/packages/router/__tests__/router-test.ts +++ b/packages/router/__tests__/router-test.ts @@ -15351,7 +15351,7 @@ describe("a router", () => { // Routes should be updated expect(t.router.routes).not.toBe(ogRoutes); - expect(t.router.routes).toBe(newRoutes); + expect(t.router.routes).toEqual(newRoutes); // Loader data should be updated and foo removed expect(t.router.state.loaderData).toEqual({ @@ -15401,7 +15401,7 @@ describe("a router", () => { // Routes should be updated expect(t.router.routes).not.toBe(ogRoutes); - expect(t.router.routes).toBe(newRoutes); + expect(t.router.routes).toEqual(newRoutes); // Loader data should be updated expect(t.router.state.loaderData).toEqual({ @@ -15467,7 +15467,7 @@ describe("a router", () => { // Routes should be updated expect(t.router.routes).not.toBe(ogRoutes); - expect(t.router.routes).toBe(newRoutes); + expect(t.router.routes).toEqual(newRoutes); // Loader data should be updated expect(t.router.state.loaderData).toEqual({ @@ -15527,7 +15527,7 @@ describe("a router", () => { // Routes should be updated expect(t.router.routes).not.toBe(ogRoutes); - expect(t.router.routes).toBe(newRoutes); + expect(t.router.routes).toEqual(newRoutes); // Loader data should be updated expect(t.router.state.loaderData).toEqual({ @@ -15582,8 +15582,8 @@ describe("a router", () => { { path: "/", id: "root", - hasErrorBoundary: true, loader: () => rootDfd2.promise, + hasErrorBoundary: true, children: [ { index: true, @@ -15616,7 +15616,7 @@ describe("a router", () => { // Routes should be updated expect(currentRouter.routes).not.toEqual(ogRoutes); - expect(currentRouter.routes).toBe(newRoutes); + expect(currentRouter.routes).toEqual(newRoutes); // Loader data should be updated expect(currentRouter.state.loaderData).toEqual({ @@ -15684,12 +15684,13 @@ describe("a router", () => { { path: "/", id: "root", - hasErrorBoundary: true, loader: () => rootDfd2.promise, + hasErrorBoundary: true, children: [ { index: true, id: "index", + hasErrorBoundary: false, }, ], }, @@ -15711,7 +15712,7 @@ describe("a router", () => { // Routes should be updated expect(currentRouter.routes).not.toEqual(ogRoutes); - expect(currentRouter.routes).toBe(newRoutes); + expect(currentRouter.routes).toEqual(newRoutes); // Loader data should be updated expect(currentRouter.state.loaderData).toEqual({ diff --git a/packages/router/router.ts b/packages/router/router.ts index 2fb88ccdde..545f006c63 100644 --- a/packages/router/router.ts +++ b/packages/router/router.ts @@ -2474,7 +2474,13 @@ export function createRouter(init: RouterInit): Router { } function _internalSetRoutes(newRoutes: AgnosticDataRouteObject[]) { - inFlightDataRoutes = newRoutes; + manifest = {}; + inFlightDataRoutes = convertRoutesToDataRoutes( + newRoutes, + mapRouteProperties, + undefined, + manifest + ); } router = {