fix(web): aggregate changes count across all repos to stop flicker (#986)

Addresses #980 — multi-repo workspaces showed a flickering / stale Changes count because the source hook returned only the last-arriving repo's status. `useSessionChangesCount` now sums file counts across the per-repo `byEnvironmentRepo` map plus commits and is wired into the three call sites; single-repo behaviour is unchanged.
This commit is contained in:
João Salavisa
2026-05-22 23:08:46 +01:00
committed by GitHub
parent db3b6dfb15
commit fb56af4e4e
5 changed files with 171 additions and 24 deletions
+2 -4
View File
@@ -10,7 +10,7 @@ import {
} from "@kandev/ui/context-menu";
import { useAppStore } from "@/components/state-provider";
import { useSessionGitStatus } from "@/hooks/domains/session/use-session-git-status";
import { useSessionCommits } from "@/hooks/domains/session/use-session-commits";
import { useSessionChangesCount } from "@/hooks/domains/session/use-session-changes-count";
import { useDockviewStore } from "@/lib/state/dockview-store";
import { cn } from "@kandev/ui/lib/utils";
import { useTabMaximizeOnDoubleClick } from "./use-tab-maximize";
@@ -40,9 +40,7 @@ export function ChangesTab(props: IDockviewPanelHeaderProps) {
const activeSessionId = useAppStore((s) => s.tasks.activeSessionId);
const gitStatus = useSessionGitStatus(activeSessionId);
const { commits } = useSessionCommits(activeSessionId ?? null);
const fileCount = gitStatus?.files ? Object.keys(gitStatus.files).length : 0;
const totalCount = fileCount + commits.length;
const totalCount = useSessionChangesCount(activeSessionId ?? null);
// gitStatus is undefined until the first WS git-status event arrives,
// which marks the end of the initial data load for this session.
@@ -22,8 +22,7 @@ import { useFileEditors } from "@/hooks/use-file-editors";
import { useLspFileOpener } from "@/hooks/use-lsp-file-opener";
import { useEditorKeybinds } from "@/hooks/use-editor-keybinds";
import { usePlanPanelAutoOpen } from "@/hooks/use-plan-panel-auto-open";
import { useSessionGitStatus } from "@/hooks/domains/session/use-session-git-status";
import { useSessionCommits } from "@/hooks/domains/session/use-session-commits";
import { useSessionChangesCount } from "@/hooks/domains/session/use-session-changes-count";
import { useEnvironmentSessionId } from "@/hooks/use-environment-session-id";
import { useActiveTaskHasRepos } from "@/hooks/domains/kanban/use-active-task-has-repos";
@@ -313,10 +312,7 @@ function ChangesContent({ panelId }: { panelId: string }) {
// Dynamic title with file count — use environment-stable sessionId so the
// tab title doesn't re-fetch on same-environment session tab switches.
const activeSessionId = useEnvironmentSessionId();
const gitStatus = useSessionGitStatus(activeSessionId);
const { commits } = useSessionCommits(activeSessionId);
const fileCount = gitStatus?.files ? Object.keys(gitStatus.files).length : 0;
const totalCount = fileCount + commits.length;
const totalCount = useSessionChangesCount(activeSessionId);
// Repo-less tasks have no git changes ever — auto-close the panel so users
// don't see a permanently empty Changes tab. Gate on a confirmed `false`: