Skip to content

Commit 3867cd8

Browse files
DavidANeilleonsenft
authored andcommitted
perf(router): Use .bind to avoid holding other closures in memory
In many JS runtimes all closures created in the same scope share a context this means that data held in one of the closures is not collected until all of the closures are collected. This change prevents the returned promise from holding a reaction that holds the entire `Router` object in memory.
1 parent 5a0f272 commit 3867cd8

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

packages/router/src/router.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,9 +697,8 @@ export class Router {
697697

698698
// Make sure that the error is propagated even though `processNavigations` catch
699699
// handler does not rethrow
700-
return promise.catch((e: any) => {
701-
return Promise.reject(e);
702-
});
700+
// perf: Use `.bind` to avoid holding the other closures in this scope while this promise is unsettled.
701+
return promise.catch(Promise.reject.bind(Promise));
703702
}
704703
}
705704

0 commit comments

Comments
 (0)