@devries-cameron20 / t3code Mirror · read-only / commits / 49bab9936e
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 23:30 UTC

fix(web): Changes row matches the diff comparison (#19553)

Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Ali Younes committed Nov 11, 2026 at 05:41 UTC 49bab9936e7ea335c31508fa5b2b5ca1a9e1ccc3
7 files changed +115 -4
apps/web/src/components/ChatView.tsx
+1
@@ -3836,6 +3836,7 @@ export default function ChatView(props: ChatViewProps) {
3836 )
3837 }
3838 gitCwd={gitCwd}
3839 + workspaceMutationId={workspaceMutationId}
3840 isGitRepo={isGitRepo}
3841 envLocked={envLocked}
3842 availableEnvironments={logicalProjectEnvironments}
apps/web/src/components/DiffPanel.tsx
+3 -2
@@ -232,7 +232,8 @@ export default function DiffPanel({
232 }));
233 const diffLayout = settings.diffLayout;
234 const [wordWrap, setWordWrap] = useState(settings.wordWrap);
235 - const [diffIgnoreWhitespace, setDiffIgnoreWhitespace] = useState(settings.diffIgnoreWhitespace);
235 + const diffIgnoreWhitespace =
236 + useDiffPanelSessionStore((state) => state.ignoreWhitespace) ?? settings.diffIgnoreWhitespace;
237 const [fileTreeOpen, setFileTreeOpen] = useLocalStorage(
238 DIFF_FILE_TREE_STORAGE_KEY,
239 false,
@@ -1222,7 +1223,7 @@ export default function DiffPanel({
1223 size="sm"
1224 pressed={diffIgnoreWhitespace}
1225 onPressedChange={(pressed) => {
1225 - setDiffIgnoreWhitespace(Boolean(pressed));
1226 + useDiffPanelSessionStore.getState().setIgnoreWhitespace(Boolean(pressed));
1227 }}
1228 />
1229 }
apps/web/src/components/GitActionsControl.logic.test.ts
+31
@@ -307,6 +307,37 @@ describe("resolveChangesTotals", () => {
307 );
308 });
309
310 + it("uses the panel's branch comparison when it has file stats", () => {
311 + const dirty = status({
312 + branchChanges: { baseRef: "main", insertions: 20, deletions: 3 },
313 + });
314 + const source = {
315 + id: "branch-range",
316 + kind: "branch-range",
317 + title: "Changes vs release",
318 + baseRef: "release",
319 + headRef: "feature/test",
320 + diff: "",
321 + diffHash: "hash",
322 + truncated: false,
323 + } as const;
324 + assert.deepEqual(
325 + resolveChangesTotals(dirty, {
326 + ...source,
327 + files: [
328 + { path: "a.ts", previousPath: null, additions: 4, deletions: 1 },
329 + { path: "b.ts", previousPath: null, additions: 2, deletions: 0 },
330 + ],
331 + }),
332 + { insertions: 6, deletions: 1, baseRef: "release" },
333 + );
334 + assert.deepEqual(resolveChangesTotals(dirty, source), {
335 + insertions: 20,
336 + deletions: 3,
337 + baseRef: "main",
338 + });
339 + });
340 +
341 it("falls back to the working tree when branchChanges is omitted", () => {
342 assert.deepInclude(
343 resolveChangesTotals(
apps/web/src/components/GitActionsControl.logic.ts
+13
@@ -1,6 +1,7 @@
1 import type {
2 GitRunStackedActionResult,
3 GitStackedAction,
4 + ReviewDiffPreviewSource,
5 VcsStatusResult,
6 } from "@t3tools/contracts";
7 import { isTemporaryWorktreeBranch } from "@t3tools/shared/git";
@@ -448,9 +449,21 @@ export type ChangesLineTotals = {
449
450 // `branchChanges ?? workingTree` treats `{0,0}` as present, so a zero branch total hid a dirty
451 // working tree and the Changes row read +0 while Diff still showed the work.
452 +// The Diff panel's branch comparison wins when it has file stats, so a remembered base or
453 +// hidden whitespace reads the same in the row as in the panel.
454 export function resolveChangesTotals(
455 status: VcsStatusResult | null | undefined,
456 + branchPreview?: ReviewDiffPreviewSource | null,
457 ): ChangesLineTotals | null {
458 + if (branchPreview?.files) {
459 + let insertions = 0;
460 + let deletions = 0;
461 + for (const file of branchPreview.files) {
462 + insertions += file.additions;
463 + deletions += file.deletions;
464 + }
465 + return { insertions, deletions, baseRef: branchPreview.baseRef };
466 + }
467 if (!status) return null;
468 const branch = status.branchChanges;
469 const tree = { ...status.workingTree, baseRef: null };
apps/web/src/components/GitActionsControl.tsx
+58 -1
@@ -94,6 +94,15 @@ import {
94 import { useQuietThreadProjection, useQuietThreadShell } from "~/state/entities";
95 import { readEnvironmentScope, useEnvironmentScope } from "~/state/session";
96 import { useEnvironmentQuery } from "~/state/query";
97 +import { useFilesystemReadAccess } from "~/state/filesystem";
98 +import { reviewEnvironment } from "~/state/review";
99 +import { revisionedQuery } from "~/state/revisionedQuery";
100 +import {
101 + selectThreadBranchBaseRef,
102 + useDiffPanelSessionStore,
103 + useDiffPanelStore,
104 +} from "~/diffPanelStore";
105 +import { useClientSettings } from "~/hooks/useSettings";
106 import { serverEnvironment } from "~/state/server";
107 import { sourceControlEnvironment } from "~/state/sourceControl";
108 import { threadEnvironment } from "~/state/threads";
@@ -122,6 +131,7 @@ interface GitActionsControlProps {
131 showActions?: boolean;
132 showChanges?: boolean;
133 onOpenChanges?: () => void;
134 + workspaceMutationId?: string | null;
135 }
136
137 interface PendingDefaultBranchAction {
@@ -933,6 +943,7 @@ export default function GitActionsControl({
943 showActions = true,
944 showChanges = true,
945 onOpenChanges,
946 + workspaceMutationId = null,
947 }: GitActionsControlProps) {
948 const panelAnchorRef = useRef<HTMLDivElement | null>(null);
949 const updateThreadMetadata = useAtomCommand(
@@ -1050,7 +1061,53 @@ export default function GitActionsControl({
1061 const isRepo = gitStatus?.isRepo ?? true;
1062 const hasPrimaryRemote = gitStatus?.hasPrimaryRemote ?? false;
1063 const gitStatusForActions = gitStatus;
1053 - const resolvedChangesTotals = resolveChangesTotals(gitStatusForActions);
1064 + const changesBaseRef = useDiffPanelStore((state) =>
1065 + selectThreadBranchBaseRef(state, activeThreadRef),
1066 + );
1067 + const ignoreWhitespaceSetting = useClientSettings((settings) => settings.diffIgnoreWhitespace);
1068 + const ignoreWhitespace =
1069 + useDiffPanelSessionStore((state) => state.ignoreWhitespace) ?? ignoreWhitespaceSetting;
1070 + const { canReadFiles } = useFilesystemReadAccess(activeEnvironmentId);
1071 + // Same input as the Diff panel's branch query, so both read one cached result. Status
1072 + // totals join the revision because edits, pulls and resets outside a turn leave the mutation
1073 + // id as is.
1074 + const changesRevision = gitStatusForActions
1075 + ? JSON.stringify([
1076 + workspaceMutationId,
1077 + gitStatusForActions.refName,
1078 + gitStatusForActions.workingTree.insertions,
1079 + gitStatusForActions.workingTree.deletions,
1080 + gitStatusForActions.branchChanges?.baseRef,
1081 + gitStatusForActions.branchChanges?.insertions,
1082 + gitStatusForActions.branchChanges?.deletions,
1083 + ])
1084 + : null;
1085 + const changesPreview = useEnvironmentQuery(
1086 + showChanges &&
1087 + isRepo &&
1088 + canReadFiles &&
1089 + changesRevision !== null &&
1090 + activeEnvironmentId !== null &&
1091 + gitCwd !== null
1092 + ? revisionedQuery(
1093 + reviewEnvironment.diffPreview({
1094 + environmentId: activeEnvironmentId,
1095 + input: {
1096 + cwd: gitCwd,
1097 + ...(changesBaseRef ? { baseRef: changesBaseRef } : {}),
1098 + ignoreWhitespace,
1099 + metadataOnly: true,
1100 + sourceKind: "branch-range",
1101 + },
1102 + }),
1103 + changesRevision,
1104 + )
1105 + : null,
1106 + );
1107 + const resolvedChangesTotals = resolveChangesTotals(
1108 + gitStatusForActions,
1109 + changesPreview.data?.sources.find((source) => source.kind === "branch-range"),
1110 + );
1111 const changesTotals = resolvedChangesTotals ?? { insertions: 0, deletions: 0 };
1112 const changesBaseLabel = resolvedChangesTotals
1113 ? resolvedChangesTotals.baseRef === null
apps/web/src/components/chat/ThreadDetailsPanel.tsx
+2
@@ -61,6 +61,7 @@ interface ThreadDetailsPanelProps extends Pick<
61 showOpenInPicker: boolean;
62 openInShortcutEnabled: boolean;
63 gitCwd: string | null;
64 + workspaceMutationId: string | null;
65 isGitRepo: boolean;
66 envLocked: boolean;
67 availableEnvironments: readonly EnvironmentOption[];
@@ -229,6 +230,7 @@ export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
230 showActions={visible.gitActions}
231 showChanges={visible.changes}
232 gitCwd={props.gitCwd}
233 + workspaceMutationId={props.workspaceMutationId}
234 activeThreadRef={activeThreadRef}
235 {...(props.draftId ? { draftId: props.draftId } : {})}
236 {...(props.onOpenChanges ? { onOpenChanges: props.onOpenChanges } : {})}
apps/web/src/diffPanelStore.ts
+7 -1
@@ -175,9 +175,13 @@ interface DiffPanelSessionStoreState {
175 defaults: ReadonlySet<string>,
176 update: (current: ReadonlySet<string>) => ReadonlySet<string>,
177 ) => void;
178 + // Null follows the diffIgnoreWhitespace setting until the panel toggle is used.
179 + ignoreWhitespace: boolean | null;
180 + setIgnoreWhitespace: (ignoreWhitespace: boolean) => void;
181 }
182
180 -// Session-only so folds survive right-panel switches without changing reload defaults.
183 +// Session-only so folds and the whitespace toggle survive right-panel switches without
184 +// changing reload defaults.
185 export const useDiffPanelSessionStore = create<DiffPanelSessionStoreState>()((set) => ({
186 collapsedFileKeysByScopeKey: {},
187 updateCollapsedFileKeys: (scopeKey, defaults, update) =>
@@ -189,6 +193,8 @@ export const useDiffPanelSessionStore = create<DiffPanelSessionStoreState>()((se
193 collapsedFileKeysByScopeKey: { ...state.collapsedFileKeysByScopeKey, [scopeKey]: next },
194 };
195 }),
196 + ignoreWhitespace: null,
197 + setIgnoreWhitespace: (ignoreWhitespace) => set({ ignoreWhitespace }),
198 }));
199
200 export function selectThreadDiffPanelSelection(