From b37cab6a038ad7459cf16ad6093116c66d86f2b6 Mon Sep 17 00:00:00 2001 From: Sheraff Date: Sun, 9 Aug 2026 22:50:02 +0200 Subject: [PATCH 1/2] perf(router-core): reuse idle match batch logic for fewer bytes --- .changeset/good-plums-doubt.md | 5 +++++ packages/router-core/src/load-client.ts | 18 ++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 .changeset/good-plums-doubt.md diff --git a/.changeset/good-plums-doubt.md b/.changeset/good-plums-doubt.md new file mode 100644 index 0000000000..d1db4aefe6 --- /dev/null +++ b/.changeset/good-plums-doubt.md @@ -0,0 +1,5 @@ +--- +'@tanstack/router-core': patch +--- + +reuse idle match batch logic for fewer bytes diff --git a/packages/router-core/src/load-client.ts b/packages/router-core/src/load-client.ts index f0024720b8..da3cfdaab5 100644 --- a/packages/router-core/src/load-client.ts +++ b/packages/router-core/src/load-client.ts @@ -1665,10 +1665,7 @@ function rollbackPublication( } finishPending(router, tx) - router.batch(() => { - router.stores.status.set('idle') - router.stores.setMatches(checkpoint.previousPresentation) - }) + setIdleMatches(router, checkpoint.previousPresentation) tx[0 /* controller */].abort() transferMatchResources(router, discarded, restored) discardBackground(router, lane) @@ -1775,10 +1772,7 @@ function restoreCommitted( if (router._tx !== tx) { return } - router.batch(() => { - router.stores.status.set('idle') - router.stores.setMatches(router._committed) - }) + setIdleMatches(router, router._committed) if (router._tx === tx) { router._commitPromise?.resolve() router._commitPromise = undefined @@ -2631,10 +2625,14 @@ export async function hydrate(router: AnyRouter): Promise { router._committed = committedMatches router._handoff = handoff router._preflight = undefined + setIdleMatches(router, presented, !needsClientLoad) +} + +function setIdleMatches(router: AnyRouter, matches: AnyRouteMatch[], skipClientLoad?: boolean) { router.batch(() => { - router.stores.setMatches(presented) + router.stores.setMatches(matches) router.stores.status.set('idle') - if (!needsClientLoad) { + if (skipClientLoad) { router.stores.resolvedLocation.set(router.stores.location.get()) } }) From bb7f463b3addaa5b1617929be87fa09e3caee6db Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sun, 9 Aug 2026 20:52:06 +0000 Subject: [PATCH 2/2] ci: apply automated fixes --- packages/router-core/src/load-client.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/router-core/src/load-client.ts b/packages/router-core/src/load-client.ts index da3cfdaab5..a56c5570d0 100644 --- a/packages/router-core/src/load-client.ts +++ b/packages/router-core/src/load-client.ts @@ -2628,7 +2628,11 @@ export async function hydrate(router: AnyRouter): Promise { setIdleMatches(router, presented, !needsClientLoad) } -function setIdleMatches(router: AnyRouter, matches: AnyRouteMatch[], skipClientLoad?: boolean) { +function setIdleMatches( + router: AnyRouter, + matches: AnyRouteMatch[], + skipClientLoad?: boolean, +) { router.batch(() => { router.stores.setMatches(matches) router.stores.status.set('idle')