The best way to control Claude Code, Codex and more from any computer or phone
fix(web): the Diff tab keeps its scope when you switch tabs (#20297)
fixfon committed
Oct 18, 2026 at 22:50 UTC
982d2ac2797f0a31ffefb16bb087872163e6efc9
3 files changed
+130
-2
apps/web/src/components/ChatView.logic.test.ts
+110
-2
@@ -15,7 +15,13 @@ import {
15
type ServerProvider,
16
} from "@t3tools/contracts";
17
import { deriveProviderInstanceEntries, NO_PROVIDER_MODEL_SELECTION } from "../providerInstances";
18
-import type { RightPanelSurface } from "../rightPanelStore";
18
+import { selectThreadDiffPanelSelection, useDiffPanelStore } from "../diffPanelStore";
19
+import {
20
+ selectActiveRightPanel,
21
+ selectThreadRightPanelState,
22
+ useRightPanelStore,
23
+ type RightPanelSurface,
24
+} from "../rightPanelStore";
25
import {
26
CommandId,
27
EnvironmentId,
@@ -26,6 +32,7 @@ import {
32
ProviderInstanceId,
33
ThreadId,
34
RunId,
35
+ type ScopedThreadRef,
36
TurnItemId,
37
type OrchestrationV2ProjectedTurnItem,
38
type WorktreeSetupSnapshot,
@@ -33,7 +40,7 @@ import {
40
import type { CodexArtifactTemplate } from "@t3tools/shared/codexArtifactTemplates";
41
import * as DateTime from "effect/DateTime";
42
import * as Option from "effect/Option";
36
-import { afterEach, describe, expect, it, vi } from "vite-plus/test";
43
+import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
44
import { Atom, AsyncResult } from "effect/reactivity";
45
import { appAtomRegistry } from "../rpc/atomRegistry";
46
import { environmentThreadDetails } from "../state/threads";
@@ -50,6 +57,7 @@ import {
57
resolveComposerProviderSelection,
58
resolveProactiveTurnDiffAction,
59
resolveDraftHeroState,
60
+ resolveExplicitDiffOpenOnActivate,
61
resolveWorktreeSetupProgress,
62
isPaintOnlyThreadTimeline,
63
peekHeldThreadTimeline,
@@ -1811,6 +1819,106 @@ describe("proactive completed diff guard", () => {
1819
});
1820
});
1821
1822
+describe("Diff scope across right-panel tab switches", () => {
1823
+ const threadRef: ScopedThreadRef = { environmentId, threadId };
1824
+ const otherThreadRef: ScopedThreadRef = { environmentId, threadId: ThreadId.make("thread-2") };
1825
+ let explicitDiffOpen: ScopedThreadRef | null = null;
1826
+
1827
+ const diffIsActive = (ref: ScopedThreadRef) =>
1828
+ selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, ref) === "diff";
1829
+ const diffScope = (ref: ScopedThreadRef) =>
1830
+ selectThreadDiffPanelSelection(useDiffPanelStore.getState().byThreadKey, ref).kind;
1831
+ const settle = (ref: ScopedThreadRef) => {
1832
+ const explicit = explicitDiffOpen;
1833
+ explicitDiffOpen = null;
1834
+ if (diffIsActive(ref) && explicit !== ref) {
1835
+ useDiffPanelStore.getState().selectGitScope(ref, "branch");
1836
+ }
1837
+ };
1838
+ const clickTab = (ref: ScopedThreadRef, surfaceId: string) => {
1839
+ const surface = selectThreadRightPanelState(
1840
+ useRightPanelStore.getState().byThreadKey,
1841
+ ref,
1842
+ ).surfaces.find((entry) => entry.id === surfaceId);
1843
+ explicitDiffOpen = resolveExplicitDiffOpenOnActivate({
1844
+ surfaceKind: surface!.kind,
1845
+ diffOpen: diffIsActive(ref),
1846
+ activeThreadRef: ref,
1847
+ });
1848
+ useRightPanelStore.getState().activateSurface(ref, surfaceId);
1849
+ settle(ref);
1850
+ };
1851
+
1852
+ beforeEach(() => {
1853
+ explicitDiffOpen = null;
1854
+ useRightPanelStore.setState({
1855
+ byThreadKey: {},
1856
+ userActionRevisionByThreadKey: {},
1857
+ closeRevisionByThreadKey: {},
1858
+ });
1859
+ useDiffPanelStore.setState({ byThreadKey: {}, branchBaseRefByThreadKey: {} });
1860
+ });
1861
+
1862
+ it("keeps Uncommitted when the user clicks back to the Diff tab", () => {
1863
+ const panels = useRightPanelStore.getState();
1864
+ panels.open(threadRef, "diff");
1865
+ settle(threadRef);
1866
+ useDiffPanelStore.getState().selectGitScope(threadRef, "unstaged");
1867
+
1868
+ panels.open(threadRef, "files");
1869
+ settle(threadRef);
1870
+ clickTab(threadRef, "diff");
1871
+
1872
+ expect(diffScope(threadRef)).toBe("unstaged");
1873
+ });
1874
+
1875
+ it("still opens on Changes for generic openings", () => {
1876
+ const panels = useRightPanelStore.getState();
1877
+ const diffStore = useDiffPanelStore.getState();
1878
+
1879
+ panels.open(threadRef, "diff");
1880
+ settle(threadRef);
1881
+ expect(diffScope(threadRef)).toBe("branch");
1882
+
1883
+ diffStore.selectGitScope(threadRef, "unstaged");
1884
+ panels.open(threadRef, "files");
1885
+ settle(threadRef);
1886
+ panels.closeSurface(threadRef, "files");
1887
+ settle(threadRef);
1888
+ expect(diffScope(threadRef)).toBe("branch");
1889
+
1890
+ diffStore.selectGitScope(threadRef, "unstaged");
1891
+ panels.open(otherThreadRef, "diff");
1892
+ diffStore.selectGitScope(otherThreadRef, "unstaged");
1893
+ settle(otherThreadRef);
1894
+ expect(diffScope(otherThreadRef)).toBe("branch");
1895
+ });
1896
+
1897
+ it("marks only a click that brings the Diff tab on screen", () => {
1898
+ expect(
1899
+ resolveExplicitDiffOpenOnActivate({
1900
+ surfaceKind: "diff",
1901
+ diffOpen: false,
1902
+ activeThreadRef: threadRef,
1903
+ }),
1904
+ ).toBe(threadRef);
1905
+ expect(
1906
+ resolveExplicitDiffOpenOnActivate({
1907
+ surfaceKind: "diff",
1908
+ diffOpen: true,
1909
+ activeThreadRef: threadRef,
1910
+ }),
1911
+ ).toBeNull();
1912
+ expect(
1913
+ resolveExplicitDiffOpenOnActivate({
1914
+ surfaceKind: "files",
1915
+ diffOpen: false,
1916
+ activeThreadRef: threadRef,
1917
+ }),
1918
+ ).toBeNull();
1919
+ });
1920
+});
1921
+
1922
describe("shouldRefocusComposerOnWindowFocus", () => {
1923
function element(
1924
tagName: string,
apps/web/src/components/ChatView.logic.ts
+14
@@ -203,6 +203,20 @@ export function resolveProactiveTurnDiffAction(input: {
203
return input.checkpoint.files.length >= 3 || changedLines >= 50 ? "open" : "ignore";
204
}
205
206
+/**
207
+ * Clicking back to an existing Diff tab resumes the review in progress, so the
208
+ * generic-open reset to Changes must skip it. A diff that is already active is
209
+ * left unmarked: the reset never runs for it, and the marker would linger into
210
+ * the next generic open.
211
+ */
212
+export function resolveExplicitDiffOpenOnActivate(input: {
213
+ readonly surfaceKind: RightPanelSurface["kind"];
214
+ readonly diffOpen: boolean;
215
+ readonly activeThreadRef: ScopedThreadRef;
216
+}): ScopedThreadRef | null {
217
+ return input.surfaceKind === "diff" && !input.diffOpen ? input.activeThreadRef : null;
218
+}
219
+
220
export function codexArtifactTemplatePromptToAppend(
221
currentDraft: string,
222
template: CodexArtifactTemplate,
apps/web/src/components/ChatView.tsx
+6
@@ -17,6 +17,7 @@ import {
17
peekHeldThreadTimeline,
18
peekRememberedThreadTimeline,
19
rememberReadyThreadTimeline,
20
+ resolveExplicitDiffOpenOnActivate,
21
resolveThreadSwitchTimeline,
22
timelineHasEphemeralPreviewUrls,
23
recallCheckoutIsRepo,
@@ -3827,6 +3828,11 @@ export default function ChatView(props: ChatViewProps) {
3828
const requestClosePanelTerminalStable = useStableCallback(requestClosePanelTerminal);
3829
const activateRightPanelSurface = (surface: RightPanelSurface) => {
3830
if (!activeThreadRef) return;
3831
+ explicitDiffOpenRef.current = resolveExplicitDiffOpenOnActivate({
3832
+ surfaceKind: surface.kind,
3833
+ diffOpen,
3834
+ activeThreadRef,
3835
+ });
3836
useRightPanelStore.getState().activateSurface(activeThreadRef, surface.id);
3837
if (surface.kind === "preview" && surface.resourceId) {
3838
setActivePreviewTab(activeThreadRef, surface.resourceId);