Skip to content

Commit

Permalink
fix: avoid uneccesary re-renders on defer resolution (#9155)
Browse files Browse the repository at this point in the history
* fix: avoid uneccesary re-renders on defer resolution

* Add changeset
  • Loading branch information
brophdawg11 authored Aug 16, 2022
1 parent c398523 commit e8dda1b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-games-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/router": patch
---

fix: avoid uneccesary re-renders on defer resolution (#9155)
4 changes: 2 additions & 2 deletions packages/react-router/__tests__/data-memory-router-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2392,7 +2392,7 @@ describe("<DataMemoryRouter>", () => {
`);

barValueDfd.resolve("LAZY");
await waitFor(() => !screen.getByText(/Loading.../));
await waitFor(() => screen.getByText(/oops is not defined/));
expect(getHtml(container)).toMatchInlineSnapshot(`
"<div>
<a
Expand Down Expand Up @@ -2466,7 +2466,7 @@ describe("<DataMemoryRouter>", () => {
`);

barValueDfd.resolve("LAZY");
await waitFor(() => !screen.getByText(/Loading.../));
await waitFor(() => screen.getByText(/oops is not defined/));
expect(getHtml(container)).toMatchInlineSnapshot(`
"<div>
<a
Expand Down
10 changes: 2 additions & 8 deletions packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1044,14 +1044,8 @@ export function createRouter(init: RouterInit): Router {
// Wire up subscribers to update loaderData as promises settle
activeDeferreds.forEach((deferredData, routeId) => {
deferredData.subscribe((aborted) => {
if (!aborted) {
updateState({
loaderData: {
...state.loaderData,
[routeId]: deferredData.data,
},
});
}
// Note: No need to updateState here since the TrackedPromise on
// loaderData is stable across resolve/reject
// Remove this instance if we were aborted or if promises have settled
if (aborted || deferredData.done) {
activeDeferreds.delete(routeId);
Expand Down

0 comments on commit e8dda1b

Please sign in to comment.