Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(client-runtime): branch list no longer resets while paging through refs (#5858)

abhwshekc7b14a8666dc
diff --git a/packages/client-runtime/src/state/vcs.ts b/packages/client-runtime/src/state/vcs.ts
index a0d4510be..042548336 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<R, E>(
runtime: Atom.AtomRuntime<EnvironmentRegistry | EnvironmentCacheStore | R, E>,
) {
- 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,