From a61bc3513fb5411b0a47f3550b2be1cc9da915e6 Mon Sep 17 00:00:00 2001 From: Sheraff Date: Sat, 16 Aug 2025 16:19:20 +0200 Subject: [PATCH 1/3] refactor(router-core): loadMatches extra microtask --- packages/router-core/src/router.ts | 40 +++++++++++------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/packages/router-core/src/router.ts b/packages/router-core/src/router.ts index 8321ed22c62..1737873f74a 100644 --- a/packages/router-core/src/router.ts +++ b/packages/router-core/src/router.ts @@ -2930,33 +2930,23 @@ export class RouterCore< } try { - await new Promise((resolveAll, rejectAll) => { - ;(async () => { - try { - // Execute all beforeLoads one by one - for (let i = 0; i < innerLoadContext.matches.length; i++) { - const beforeLoad = this.handleBeforeLoad(innerLoadContext, i) - if (isPromise(beforeLoad)) await beforeLoad - } - - // Execute all loaders in parallel - const max = - innerLoadContext.firstBadMatchIndex ?? - innerLoadContext.matches.length - for (let i = 0; i < max; i++) { - innerLoadContext.matchPromises.push( - this.loadRouteMatch(innerLoadContext, i), - ) - } + // Execute all beforeLoads one by one + for (let i = 0; i < innerLoadContext.matches.length; i++) { + const beforeLoad = this.handleBeforeLoad(innerLoadContext, i) + if (isPromise(beforeLoad)) await beforeLoad + } - await Promise.all(innerLoadContext.matchPromises) + // Execute all loaders in parallel + const max = + innerLoadContext.firstBadMatchIndex ?? + innerLoadContext.matches.length + for (let i = 0; i < max; i++) { + innerLoadContext.matchPromises.push( + this.loadRouteMatch(innerLoadContext, i), + ) + } + await Promise.all(innerLoadContext.matchPromises) - resolveAll() - } catch (err) { - rejectAll(err) - } - })() - }) const readyPromise = this.triggerOnReady(innerLoadContext) if (isPromise(readyPromise)) await readyPromise } catch (err) { From cb1f4978b3a7d7445daccc8372c73281471b48e0 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sat, 16 Aug 2025 14:20:16 +0000 Subject: [PATCH 2/3] ci: apply automated fixes --- packages/router-core/src/router.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/router-core/src/router.ts b/packages/router-core/src/router.ts index 1737873f74a..5b36456e944 100644 --- a/packages/router-core/src/router.ts +++ b/packages/router-core/src/router.ts @@ -2938,8 +2938,7 @@ export class RouterCore< // Execute all loaders in parallel const max = - innerLoadContext.firstBadMatchIndex ?? - innerLoadContext.matches.length + innerLoadContext.firstBadMatchIndex ?? innerLoadContext.matches.length for (let i = 0; i < max; i++) { innerLoadContext.matchPromises.push( this.loadRouteMatch(innerLoadContext, i), From f9e3daadc23860a23f53b478edd116c1bb9a28c0 Mon Sep 17 00:00:00 2001 From: Sheraff Date: Sat, 16 Aug 2025 17:20:31 +0200 Subject: [PATCH 3/3] update store-updates test w/ lower number --- .../react-router/tests/store-updates-during-navigation.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-router/tests/store-updates-during-navigation.test.tsx b/packages/react-router/tests/store-updates-during-navigation.test.tsx index 8768f65895b..2b35683ef54 100644 --- a/packages/react-router/tests/store-updates-during-navigation.test.tsx +++ b/packages/react-router/tests/store-updates-during-navigation.test.tsx @@ -183,7 +183,7 @@ describe("Store doesn't update *too many* times during navigation", () => { // This number should be as small as possible to minimize the amount of work // that needs to be done during a navigation. // Any change that increases this number should be investigated. - expect(updates).toBe(8) + expect(updates).toBe(7) }) test('hover preload, then navigate, w/ async loaders', async () => {