GeezerVison is showing github.com — fix(web): a branch switch no longer waits behind the previous PR lookup · pingdotgg/t3code@530fb04
File treeExpand file treeCollapse file tree Open diff view settings packages/client-runtime/src/state
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/BranchToolbarBranchSelector.tsx +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -126,7 +126,7 @@ export function BranchToolbarBranchSelector({ | 126 | 126 | const switchRef = useAtomCommand(vcsEnvironment.switchRef, { | 127 | 127 | reportFailure: false, | 128 | 128 | }); | 129 | | - const refreshStatus = useAtomCommand(vcsEnvironment.refreshStatus, { | | 129 | + const refreshLocalStatusForPicker = useAtomCommand(vcsEnvironment.refreshLocalStatusForPicker, { | 130 | 130 | reportFailure: false, | 131 | 131 | }); | 132 | 132 | const createRefMutation = useAtomCommand(vcsEnvironment.createRef, { | @@ -508,7 +508,10 @@ export function BranchToolbarBranchSelector({ | 508 | 508 | const handleOpenChange = (open: boolean) => { | 509 | 509 | setIsBranchMenuOpen(open); | 510 | 510 | 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 | + }); | 512 | 515 | } | 513 | 516 | if (!open) { | 514 | 517 | setBranchQuery(""); | |
Collapse file Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/vcs.test.ts +61Lines changed: 61 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -282,6 +282,67 @@ describe("cached VCS refs", () => { | 282 | 282 | ), | 283 | 283 | ); | 284 | 284 |
| | 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 | + | 285 | 346 | it.effect("suppresses persisted snapshots after an environment-wide clear fails", () => | 286 | 347 | Effect.scoped( | 287 | 348 | Effect.gen(function* () { | |
Collapse file Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/vcs.ts +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -310,6 +310,13 @@ export function createVcsEnvironmentAtoms<R, E>( | 310 | 310 | concurrency: vcsCommandConcurrency, | 311 | 311 | onSettled: invalidateRefs, | 312 | 312 | }), | | 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 | + }), | 313 | 320 | createWorktree: createEnvironmentRpcCommand(runtime, { | 314 | 321 | label: "environment-data:vcs:create-worktree", | 315 | 322 | tag: WS_METHODS.vcsCreateWorktree, | |
|