From c7b14a8666dc44ee426f8d139e0493af9fe4b6db Mon Sep 17 00:00:00 2001 From: abhwshek <67309069+a20hek@users.noreply.github.com> Date: Sat, 15 Aug 2026 17:32:21 +0530 Subject: [PATCH] fix(client-runtime): branch list no longer resets while paging through refs (#5858) --- packages/client-runtime/src/state/vcs.ts | 41 +++++++++++++----------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/packages/client-runtime/src/state/vcs.ts b/packages/client-runtime/src/state/vcs.ts index a0d4510be7f59b666f7190aab948fbf8f64607f3..042548336720e5bcd43f233001699fa2dc1cb664 100644 --- a/packages/client-runtime/src/state/vcs.ts +++ b/packages/client-runtime/src/state/vcs.ts @@ -236,29 +236,32 @@ export function cachedVcsRefsChanges( export function createVcsEnvironmentAtoms( runtime: Atom.AtomRuntime, ) { - const listRefsByEnvironment = Atom.family((environmentId: EnvironmentId) => - Atom.family((inputKey: string) => { - const input = JSON.parse(inputKey) as VcsListRefsInput; - return runtime - .atom((get) => { - const state = get(vcsRefsCacheStateAtom({ environmentId })); - return cachedVcsRefsChanges( - environmentId, - input, - state.revision, - state.persistedCacheReadable, - ); - }) - .pipe( - Atom.setIdleTTL(VCS_REFS_IDLE_TTL_MS), - Atom.withLabel(`environment-data:vcs:list-refs:${environmentId}:${inputKey}`), + /** + * One flat family on purpose: families hold entries via WeakRef, so a nested + * per-environment family can be collected between lookups, dropping every + * cached page atom and collapsing paginated ref lists mid-scroll. + */ + const listRefsFamily = Atom.family((key: string) => { + const [environmentId, input] = JSON.parse(key) as [EnvironmentId, VcsListRefsInput]; + return runtime + .atom((get) => { + const state = get(vcsRefsCacheStateAtom({ environmentId })); + return cachedVcsRefsChanges( + environmentId, + input, + state.revision, + state.persistedCacheReadable, ); - }), - ); + }) + .pipe( + Atom.setIdleTTL(VCS_REFS_IDLE_TTL_MS), + Atom.withLabel(`environment-data:vcs:list-refs:${key}`), + ); + }); const listRefs = (target: { readonly environmentId: EnvironmentId; readonly input: VcsListRefsInput; - }) => listRefsByEnvironment(target.environmentId)(JSON.stringify(target.input)); + }) => listRefsFamily(JSON.stringify([target.environmentId, target.input])); const invalidateRefs = ( target: { readonly environmentId: EnvironmentId; readonly input: { readonly cwd: string } }, registry: AtomRegistry.AtomRegistry, -- 2.54.0