diff --git a/apps/server/src/git/Layers/GitStatusBroadcaster.ts b/apps/server/src/git/Layers/GitStatusBroadcaster.ts index 992b91e143..78d4abf40d 100644 --- a/apps/server/src/git/Layers/GitStatusBroadcaster.ts +++ b/apps/server/src/git/Layers/GitStatusBroadcaster.ts @@ -222,23 +222,22 @@ export const GitStatusBroadcasterLive = Layer.effect( }; const retainRemotePoller = Effect.fn("retainRemotePoller")(function* (cwd: string) { - const normalizedCwd = normalizeCwd(cwd); yield* SynchronizedRef.modifyEffect(pollersRef, (activePollers) => { - const existing = activePollers.get(normalizedCwd); + const existing = activePollers.get(cwd); if (existing) { const nextPollers = new Map(activePollers); - nextPollers.set(normalizedCwd, { + nextPollers.set(cwd, { ...existing, subscriberCount: existing.subscriberCount + 1, }); return Effect.succeed([undefined, nextPollers] as const); } - return makeRemoteRefreshLoop(normalizedCwd).pipe( + return makeRemoteRefreshLoop(cwd).pipe( Effect.forkIn(broadcasterScope), Effect.map((fiber) => { const nextPollers = new Map(activePollers); - nextPollers.set(normalizedCwd, { + nextPollers.set(cwd, { fiber, subscriberCount: 1, }); @@ -249,16 +248,15 @@ export const GitStatusBroadcasterLive = Layer.effect( }); const releaseRemotePoller = Effect.fn("releaseRemotePoller")(function* (cwd: string) { - const normalizedCwd = normalizeCwd(cwd); const pollerToInterrupt = yield* SynchronizedRef.modify(pollersRef, (activePollers) => { - const existing = activePollers.get(normalizedCwd); + const existing = activePollers.get(cwd); if (!existing) { return [null, activePollers] as const; } if (existing.subscriberCount > 1) { const nextPollers = new Map(activePollers); - nextPollers.set(normalizedCwd, { + nextPollers.set(cwd, { ...existing, subscriberCount: existing.subscriberCount - 1, }); @@ -266,7 +264,7 @@ export const GitStatusBroadcasterLive = Layer.effect( } const nextPollers = new Map(activePollers); - nextPollers.delete(normalizedCwd); + nextPollers.delete(cwd); return [existing.fiber, nextPollers] as const; }); diff --git a/apps/web/src/lib/gitStatusState.test.ts b/apps/web/src/lib/gitStatusState.test.ts index 14f1f355d4..757130db9b 100644 --- a/apps/web/src/lib/gitStatusState.test.ts +++ b/apps/web/src/lib/gitStatusState.test.ts @@ -54,6 +54,15 @@ afterEach(() => { }); describe("gitStatusState", () => { + it("starts fresh cwd state in a pending state", () => { + expect(getGitStatusSnapshot("/fresh")).toEqual({ + data: null, + error: null, + cause: null, + isPending: true, + }); + }); + it("shares one live subscription per cwd and updates the per-cwd atom snapshot", () => { const releaseA = watchGitStatus("/repo", gitClient); const releaseB = watchGitStatus("/repo", gitClient); diff --git a/apps/web/src/lib/gitStatusState.ts b/apps/web/src/lib/gitStatusState.ts index 73e6974da0..1c1cf00864 100644 --- a/apps/web/src/lib/gitStatusState.ts +++ b/apps/web/src/lib/gitStatusState.ts @@ -29,6 +29,10 @@ const EMPTY_GIT_STATUS_STATE = Object.freeze({ cause: null, isPending: false, }); +const INITIAL_GIT_STATUS_STATE = Object.freeze({ + ...EMPTY_GIT_STATUS_STATE, + isPending: true, +}); const EMPTY_GIT_STATUS_ATOM = Atom.make(EMPTY_GIT_STATUS_STATE).pipe( Atom.keepAlive, Atom.withLabel("git-status:null"), @@ -46,7 +50,7 @@ let sharedGitStatusClient: GitStatusClient | null = null; const gitStatusStateAtom = Atom.family((cwd: string) => { knownGitStatusCwds.add(cwd); - return Atom.make(EMPTY_GIT_STATUS_STATE).pipe( + return Atom.make(INITIAL_GIT_STATUS_STATE).pipe( Atom.keepAlive, Atom.withLabel(`git-status:${cwd}`), ); @@ -122,7 +126,7 @@ export function resetGitStatusStateForTests(): void { sharedGitStatusClient = null; for (const cwd of knownGitStatusCwds) { - appAtomRegistry.set(gitStatusStateAtom(cwd), EMPTY_GIT_STATUS_STATE); + appAtomRegistry.set(gitStatusStateAtom(cwd), INITIAL_GIT_STATUS_STATE); } knownGitStatusCwds.clear(); } @@ -198,7 +202,7 @@ function markGitStatusPending(cwd: string): void { const current = appAtomRegistry.get(atom); const next = current.data === null - ? { ...EMPTY_GIT_STATUS_STATE, isPending: true } + ? INITIAL_GIT_STATUS_STATE : { ...current, error: null,