Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/good-plums-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/router-core': patch
---

reuse idle match batch logic for fewer bytes
22 changes: 12 additions & 10 deletions packages/router-core/src/load-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2631,10 +2625,18 @@ export async function hydrate(router: AnyRouter): Promise<void> {
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())
}
})
Expand Down
Loading