Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hmr-error-boundary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/router": patch
---

Fix HMR-driven error boundaries by properly reconstructing new routes and `manifest` in `\_internalSetRoutes`
17 changes: 9 additions & 8 deletions packages/router/__tests__/router-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -15582,8 +15582,8 @@ describe("a router", () => {
{
path: "/",
id: "root",
hasErrorBoundary: true,
loader: () => rootDfd2.promise,
hasErrorBoundary: true,
children: [
{
index: true,
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -15684,12 +15684,13 @@ describe("a router", () => {
{
path: "/",
id: "root",
hasErrorBoundary: true,
loader: () => rootDfd2.promise,
hasErrorBoundary: true,
children: [
{
index: true,
id: "index",
hasErrorBoundary: false,
},
],
},
Expand All @@ -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({
Expand Down
8 changes: 7 additions & 1 deletion packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2474,7 +2474,13 @@ export function createRouter(init: RouterInit): Router {
}

function _internalSetRoutes(newRoutes: AgnosticDataRouteObject[]) {
inFlightDataRoutes = newRoutes;
manifest = {};
inFlightDataRoutes = convertRoutesToDataRoutes(
newRoutes,
mapRouteProperties,
undefined,
manifest
);
}

router = {
Expand Down