Skip to content

Commit 530fb04

Browse files
Yuruzuuclaude
andcommitted
fix(web): a branch switch no longer waits behind the previous PR lookup
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b50d8a1 commit 530fb04

3 files changed

Lines changed: 73 additions & 2 deletions

File tree

‎apps/web/src/components/BranchToolbarBranchSelector.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export function BranchToolbarBranchSelector({
126126
const switchRef = useAtomCommand(vcsEnvironment.switchRef, {
127127
reportFailure: false,
128128
});
129-
const refreshStatus = useAtomCommand(vcsEnvironment.refreshStatus, {
129+
const refreshLocalStatusForPicker = useAtomCommand(vcsEnvironment.refreshLocalStatusForPicker, {
130130
reportFailure: false,
131131
});
132132
const createRefMutation = useAtomCommand(vcsEnvironment.createRef, {
@@ -508,7 +508,10 @@ export function BranchToolbarBranchSelector({
508508
const handleOpenChange = (open: boolean) => {
509509
setIsBranchMenuOpen(open);
510510
if (open && !isBranchMenuOpen && branchCwd !== null) {
511-
void refreshStatus({ environmentId, input: { cwd: branchCwd, localOnly: true } });
511+
void refreshLocalStatusForPicker({
512+
environmentId,
513+
input: { cwd: branchCwd, localOnly: true },
514+
});
512515
}
513516
if (!open) {
514517
setBranchQuery("");

‎packages/client-runtime/src/state/vcs.test.ts‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,67 @@ describe("cached VCS refs", () => {
282282
),
283283
);
284284

285+
it.effect("a checkout does not wait behind a picker's local status refresh", () =>
286+
Effect.scoped(
287+
Effect.gen(function* () {
288+
const refreshStarted = yield* Deferred.make<void>();
289+
const releaseRefresh = yield* Deferred.make<void>();
290+
const client = {
291+
[WS_METHODS.vcsRefreshStatus]: () =>
292+
Deferred.succeed(refreshStarted, undefined).pipe(
293+
Effect.andThen(Deferred.await(releaseRefresh)),
294+
),
295+
[WS_METHODS.vcsSwitchRef]: () => Effect.succeed({ refName: "feature" }),
296+
} as unknown as WsRpcProtocolClient;
297+
const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
298+
target: TARGET,
299+
state: yield* SubscriptionRef.make(CONNECTED_CONNECTION_STATE),
300+
session: yield* SubscriptionRef.make(Option.some(session(client))),
301+
prepared: yield* SubscriptionRef.make(Option.none<PreparedConnection>()),
302+
connect: Effect.void,
303+
disconnect: Effect.void,
304+
retryNow: Effect.void,
305+
} satisfies EnvironmentSupervisor.EnvironmentSupervisor["Service"]);
306+
const run: EnvironmentRegistry.EnvironmentRegistry["Service"]["run"] = (
307+
_environmentId,
308+
effect,
309+
) => Effect.provideService(effect, EnvironmentSupervisor.EnvironmentSupervisor, supervisor);
310+
const runtime = Atom.runtime(
311+
Layer.merge(
312+
Layer.succeed(
313+
EnvironmentRegistry.EnvironmentRegistry,
314+
EnvironmentRegistry.EnvironmentRegistry.of({
315+
run,
316+
} as unknown as EnvironmentRegistry.EnvironmentRegistry["Service"]),
317+
),
318+
Layer.succeed(Persistence.EnvironmentCacheStore, cacheWithRefs(Option.none())),
319+
),
320+
);
321+
const atoms = createVcsEnvironmentAtoms(runtime);
322+
const registry = yield* Effect.acquireRelease(Effect.sync(AtomRegistry.make), (registry) =>
323+
Effect.sync(() => registry.dispose()),
324+
);
325+
const target = { environmentId: TARGET.environmentId, input: { cwd: "/repo" } };
326+
327+
const refresh = atoms.refreshLocalStatusForPicker.run(registry, {
328+
...target,
329+
input: { cwd: "/repo", localOnly: true },
330+
});
331+
yield* Deferred.await(refreshStarted);
332+
const checkout = yield* Effect.promise(() =>
333+
atoms.switchRef.run(registry, {
334+
...target,
335+
input: { cwd: "/repo", refName: "feature" },
336+
}),
337+
);
338+
339+
expect(AsyncResult.isSuccess(checkout)).toBe(true);
340+
yield* Deferred.succeed(releaseRefresh, undefined);
341+
expect(AsyncResult.isSuccess(yield* Effect.promise(() => refresh))).toBe(true);
342+
}),
343+
),
344+
);
345+
285346
it.effect("suppresses persisted snapshots after an environment-wide clear fails", () =>
286347
Effect.scoped(
287348
Effect.gen(function* () {

‎packages/client-runtime/src/state/vcs.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,13 @@ export function createVcsEnvironmentAtoms<R, E>(
310310
concurrency: vcsCommandConcurrency,
311311
onSettled: invalidateRefs,
312312
}),
313+
// Outside the serial queue: on the server this waits for any running PR lookup, and a checkout
314+
// picked right after opening a picker must not wait behind it.
315+
refreshLocalStatusForPicker: createEnvironmentRpcCommand(runtime, {
316+
label: "environment-data:vcs:refresh-local-status-for-picker",
317+
tag: WS_METHODS.vcsRefreshStatus,
318+
onSettled: invalidateRefs,
319+
}),
313320
createWorktree: createEnvironmentRpcCommand(runtime, {
314321
label: "environment-data:vcs:create-worktree",
315322
tag: WS_METHODS.vcsCreateWorktree,

0 commit comments

Comments
 (0)