Skip to content

Commit 4692667

Browse files
fix: surface errors to the proper error boundary after _internalSetRoutes (#10437)
* fix: surface errors to the proper error boundary after _internalSetRoutes * Update .changeset/hmr-error-boundary.md --------- Co-authored-by: Matt Brophy <[email protected]>
1 parent c4e9607 commit 4692667

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

.changeset/hmr-error-boundary.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/router": patch
3+
---
4+
5+
Fix HMR-driven error boundaries by properly reconstructing new routes and `manifest` in `\_internalSetRoutes`

packages/router/__tests__/router-test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15351,7 +15351,7 @@ describe("a router", () => {
1535115351

1535215352
// Routes should be updated
1535315353
expect(t.router.routes).not.toBe(ogRoutes);
15354-
expect(t.router.routes).toBe(newRoutes);
15354+
expect(t.router.routes).toEqual(newRoutes);
1535515355

1535615356
// Loader data should be updated and foo removed
1535715357
expect(t.router.state.loaderData).toEqual({
@@ -15401,7 +15401,7 @@ describe("a router", () => {
1540115401

1540215402
// Routes should be updated
1540315403
expect(t.router.routes).not.toBe(ogRoutes);
15404-
expect(t.router.routes).toBe(newRoutes);
15404+
expect(t.router.routes).toEqual(newRoutes);
1540515405

1540615406
// Loader data should be updated
1540715407
expect(t.router.state.loaderData).toEqual({
@@ -15467,7 +15467,7 @@ describe("a router", () => {
1546715467

1546815468
// Routes should be updated
1546915469
expect(t.router.routes).not.toBe(ogRoutes);
15470-
expect(t.router.routes).toBe(newRoutes);
15470+
expect(t.router.routes).toEqual(newRoutes);
1547115471

1547215472
// Loader data should be updated
1547315473
expect(t.router.state.loaderData).toEqual({
@@ -15527,7 +15527,7 @@ describe("a router", () => {
1552715527

1552815528
// Routes should be updated
1552915529
expect(t.router.routes).not.toBe(ogRoutes);
15530-
expect(t.router.routes).toBe(newRoutes);
15530+
expect(t.router.routes).toEqual(newRoutes);
1553115531

1553215532
// Loader data should be updated
1553315533
expect(t.router.state.loaderData).toEqual({
@@ -15582,8 +15582,8 @@ describe("a router", () => {
1558215582
{
1558315583
path: "/",
1558415584
id: "root",
15585-
hasErrorBoundary: true,
1558615585
loader: () => rootDfd2.promise,
15586+
hasErrorBoundary: true,
1558715587
children: [
1558815588
{
1558915589
index: true,
@@ -15616,7 +15616,7 @@ describe("a router", () => {
1561615616

1561715617
// Routes should be updated
1561815618
expect(currentRouter.routes).not.toEqual(ogRoutes);
15619-
expect(currentRouter.routes).toBe(newRoutes);
15619+
expect(currentRouter.routes).toEqual(newRoutes);
1562015620

1562115621
// Loader data should be updated
1562215622
expect(currentRouter.state.loaderData).toEqual({
@@ -15684,12 +15684,13 @@ describe("a router", () => {
1568415684
{
1568515685
path: "/",
1568615686
id: "root",
15687-
hasErrorBoundary: true,
1568815687
loader: () => rootDfd2.promise,
15688+
hasErrorBoundary: true,
1568915689
children: [
1569015690
{
1569115691
index: true,
1569215692
id: "index",
15693+
hasErrorBoundary: false,
1569315694
},
1569415695
],
1569515696
},
@@ -15711,7 +15712,7 @@ describe("a router", () => {
1571115712

1571215713
// Routes should be updated
1571315714
expect(currentRouter.routes).not.toEqual(ogRoutes);
15714-
expect(currentRouter.routes).toBe(newRoutes);
15715+
expect(currentRouter.routes).toEqual(newRoutes);
1571515716

1571615717
// Loader data should be updated
1571715718
expect(currentRouter.state.loaderData).toEqual({

packages/router/router.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2474,7 +2474,13 @@ export function createRouter(init: RouterInit): Router {
24742474
}
24752475

24762476
function _internalSetRoutes(newRoutes: AgnosticDataRouteObject[]) {
2477-
inFlightDataRoutes = newRoutes;
2477+
manifest = {};
2478+
inFlightDataRoutes = convertRoutesToDataRoutes(
2479+
newRoutes,
2480+
mapRouteProperties,
2481+
undefined,
2482+
manifest
2483+
);
24782484
}
24792485

24802486
router = {

0 commit comments

Comments
 (0)