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..a56c5570d0 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,18 @@ 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()) } })