Skip to content

Commit ad8081d

Browse files
committed
Fix sidebar creating per-thread WebSocket subscriptions for git status
Use passive git status read (useGitStatusPassive) in SidebarThreadRow instead of useGitStatus, which creates WebSocket stream subscriptions. The sidebar only needs to display cached PR badge data from git status that is already being subscribed to by the active thread's BranchToolbar. This avoids creating one server-side remote poller per unique worktree path visible in the sidebar.
1 parent acb9bf1 commit ad8081d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

apps/web/src/components/Sidebar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import {
6969
threadJumpIndexFromCommand,
7070
threadTraversalDirectionFromCommand,
7171
} from "../keybindings";
72-
import { useGitStatus } from "../lib/gitStatusState";
72+
import { useGitStatusPassive } from "../lib/gitStatusState";
7373
import { readNativeApi } from "../nativeApi";
7474
import { useComposerDraftStore } from "../composerDraftStore";
7575
import { useHandleNewThread } from "../hooks/useHandleNewThread";
@@ -298,7 +298,7 @@ function SidebarThreadRow(props: SidebarThreadRowProps) {
298298
selectThreadTerminalState(state.terminalStateByThreadId, props.threadId).runningTerminalIds,
299299
);
300300
const gitCwd = thread?.worktreePath ?? props.projectCwd;
301-
const gitStatus = useGitStatus(thread?.branch != null ? gitCwd : null);
301+
const gitStatus = useGitStatusPassive(thread?.branch != null ? gitCwd : null);
302302

303303
if (!thread) {
304304
return null;

apps/web/src/lib/gitStatusState.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ export function useGitStatus(cwd: string | null): GitStatusState {
134134
return cwd === null ? EMPTY_GIT_STATUS_STATE : state;
135135
}
136136

137+
/**
138+
* Passively reads the current git status for a cwd without creating a
139+
* WebSocket subscription. Use this when you only need to display cached
140+
* status data (e.g. sidebar PR badges) without driving server-side polling.
141+
*/
142+
export function useGitStatusPassive(cwd: string | null): GitStatusState {
143+
const state = useAtomValue(cwd !== null ? gitStatusStateAtom(cwd) : EMPTY_GIT_STATUS_ATOM);
144+
return cwd === null ? EMPTY_GIT_STATUS_STATE : state;
145+
}
146+
137147
function ensureGitStatusClient(client: GitStatusClient): void {
138148
if (sharedGitStatusClient === client) {
139149
return;

0 commit comments

Comments
 (0)