From 3867cd85545bfb5bde9e92d46467651337b2b7ae Mon Sep 17 00:00:00 2001 From: David Neil Date: Mon, 2 Feb 2026 10:35:44 -0700 Subject: [PATCH] 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. --- packages/router/src/router.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/router/src/router.ts b/packages/router/src/router.ts index ed45df2e36e..9f1c755d574 100644 --- a/packages/router/src/router.ts +++ b/packages/router/src/router.ts @@ -697,9 +697,8 @@ export class Router { // Make sure that the error is propagated even though `processNavigations` catch // handler does not rethrow - return promise.catch((e: any) => { - return Promise.reject(e); - }); + // perf: Use `.bind` to avoid holding the other closures in this scope while this promise is unsettled. + return promise.catch(Promise.reject.bind(Promise)); } }