@devries-cameron20 / t3code-1 / commits / b03534fa7b
Fork 0

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

fix(web): Git actions follow the selected thread (#18862)

Yash Singh committed Oct 12, 2026 at 19:15 UTC b03534fa7b847e8403322e416189c6293e6846e0
3 files changed +258 -18
apps/web/src/components/GitActionsControl.lifecycle.test.ts new
+234
@@ -0,0 +1,234 @@
1 +// @vitest-environment jsdom
2 +import { AuthSourceControlWriteScope, EnvironmentId, ThreadId } from "@t3tools/contracts";
3 +import { AsyncResult } from "effect/reactivity";
4 +import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
5 +
6 +const state = vi.hoisted(() => ({
7 + actions: [] as {
8 + scope: { environmentId: string | null; cwd: string | null };
9 + input: { threadId?: string; action: string };
10 + }[],
11 + toasts: [] as { type?: string; description?: string; actionProps?: { onClick: () => void } }[],
12 + scopes: new Set<string>(),
13 + primaryScopes: new Set<string>(),
14 +}));
15 +
16 +vi.mock("@effect/atom-react", () => ({
17 + useAtomValue: (atom: unknown) => (atom === "vcs-state" ? { isRunning: false } : null),
18 +}));
19 +vi.mock("~/state/entities", () => ({
20 + useThreadProjection: () => null,
21 + useThreadShell: (ref: { threadId: string }) => ({ branch: "main", id: ref.threadId }),
22 +}));
23 +vi.mock("~/state/session", () => ({
24 + useEnvironmentScope: (environmentId: unknown, scope: string) =>
25 + (environmentId === "environment" ? state.scopes : state.primaryScopes).has(scope),
26 + readEnvironmentScope: (environmentId: unknown, scope: string) =>
27 + (environmentId === "environment" ? state.scopes : state.primaryScopes).has(scope),
28 +}));
29 +vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: (command: unknown) => command }));
30 +vi.mock("~/state/server", () => ({ serverEnvironment: { configValueAtom: () => null } }));
31 +vi.mock("~/state/sourceControl", () => ({ sourceControlEnvironment: { discovery: () => null } }));
32 +vi.mock("~/state/vcs", () => ({
33 + vcsEnvironment: { status: () => null },
34 + vcsActionManager: { stateAtom: () => "vcs-state" },
35 +}));
36 +vi.mock("~/state/threads", () => ({
37 + threadEnvironment: { updateMetadata: async () => AsyncResult.success(undefined) },
38 +}));
39 +vi.mock("~/state/query", () => ({
40 + useEnvironmentQuery: () => ({
41 + data: {
42 + sourceControlProviders: [],
43 + isRepo: true,
44 + refName: "main",
45 + isDefaultRef: false,
46 + hasPrimaryRemote: true,
47 + hasWorkingTreeChanges: true,
48 + workingTree: {
49 + files: [{ path: "file.ts", status: "modified", insertions: 1, deletions: 0 }],
50 + },
51 + },
52 + error: null,
53 + }),
54 +}));
55 +vi.mock("@tanstack/react-router", () => ({ useNavigate: () => () => {} }));
56 +vi.mock("~/composerDraftStore", () => ({
57 + useComposerDraftStore: (
58 + select: (store: {
59 + getDraftSession: () => null;
60 + getDraftThreadByRef: () => null;
61 + setDraftThreadContext: () => void;
62 + }) => unknown,
63 + ) =>
64 + select({
65 + getDraftSession: () => null,
66 + getDraftThreadByRef: () => null,
67 + setDraftThreadContext: () => {},
68 + }),
69 +}));
70 +vi.mock("~/lib/sourceControlActions", () => ({
71 + useSourceControlActionRunning: () => false,
72 + useVcsInitAction: () => ({}),
73 + useVcsPullAction: () => ({}),
74 + useSourceControlPublishRepositoryAction: () => ({}),
75 + useGitStackedAction: (scope: { environmentId: string | null; cwd: string | null }) => ({
76 + run: async (input: { featureBranch?: boolean; threadId?: string; action: string }) => {
77 + state.actions.push({ scope, input });
78 + return {
79 + _tag: "Success",
80 + value: {
81 + branch: { status: "skipped_not_requested" },
82 + toast: {
83 + title: "Committed",
84 + description: "Committed",
85 + cta: {
86 + kind: "run_action",
87 + label: "Push & create PR",
88 + action: { kind: "commit_push_pr" },
89 + },
90 + },
91 + },
92 + };
93 + },
94 + }),
95 +}));
96 +vi.mock("~/lib/utils", () => ({ cn: () => "", randomUUID: () => "action" }));
97 +vi.mock("~/editorPreferences", () => ({ useOpenInPreferredEditor: () => () => {} }));
98 +vi.mock("~/browser/useOpenLink", () => ({ useOpenLink: () => () => {} }));
99 +vi.mock("~/lib/openPullRequestLink", () => ({ useOpenPrLink: () => () => {} }));
100 +vi.mock("~/components/ui/toast", () => ({
101 + stackedThreadToast: (input: unknown) => input,
102 + toastManager: {
103 + add: (input: {
104 + type?: string;
105 + description?: string;
106 + actionProps?: { onClick: () => void };
107 + }) => {
108 + state.toasts.push(input);
109 + return "toast";
110 + },
111 + update: () => {},
112 + close: () => {},
113 + },
114 +}));
115 +vi.mock("~/components/ui/dialog", () => ({
116 + Dialog: "Dialog",
117 + DialogDescription: "DialogDescription",
118 + DialogFooter: "DialogFooter",
119 + DialogHeader: "DialogHeader",
120 + DialogPanel: "DialogPanel",
121 + DialogPopup: "DialogPopup",
122 + DialogTitle: "DialogTitle",
123 +}));
124 +vi.mock("~/components/ui/group", () => ({ Group: "Group", GroupSeparator: "GroupSeparator" }));
125 +vi.mock("~/components/ui/menu", () => ({
126 + Menu: "Menu",
127 + MenuItem: "MenuItem",
128 + MenuItemLabel: "MenuItemLabel",
129 + MenuPopup: "MenuPopup",
130 + MenuTrigger: "MenuTrigger",
131 +}));
132 +vi.mock("~/components/ui/popover", () => ({
133 + Popover: "Popover",
134 + PopoverPopup: "PopoverPopup",
135 + PopoverTrigger: "PopoverTrigger",
136 +}));
137 +vi.mock("~/components/ui/tooltip", () => ({
138 + Tooltip: "Tooltip",
139 + TooltipPopup: "TooltipPopup",
140 + TooltipTrigger: "TooltipTrigger",
141 +}));
142 +vi.mock("~/components/ui/button", () => ({ Button: "button" }));
143 +vi.mock("~/components/ui/checkbox", () => ({ Checkbox: "Checkbox" }));
144 +vi.mock("~/components/ui/input", () => ({ Input: "Input" }));
145 +vi.mock("~/components/ui/radio-group", () => ({ RadioGroup: "RadioGroup" }));
146 +vi.mock("~/components/ui/scroll-area", () => ({ ScrollArea: "ScrollArea" }));
147 +vi.mock("~/components/ui/spinner", () => ({ Spinner: "Spinner" }));
148 +vi.mock("~/components/ui/textarea", () => ({ Textarea: "Textarea" }));
149 +vi.mock("~/components/ui/toggle", () => ({ toggleVariants: () => "" }));
150 +vi.mock("./AnimatedHeight", () => ({ AnimatedHeight: "AnimatedHeight" }));
151 +
152 +import GitActionsControl from "./GitActionsControl";
153 +
154 +import { createElement, memo } from "react";
155 +import { act, create } from "react-test-renderer";
156 +
157 +vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
158 +
159 +const renderers: ReturnType<typeof create>[] = [];
160 +// ThreadDetailsPanel keeps this component mounted behind React.memo when threads change.
161 +const MemoGitActionsControl = memo(GitActionsControl);
162 +const props = (thread: string, cwd: string) => ({
163 + gitCwd: cwd,
164 + activeThreadRef: {
165 + environmentId: EnvironmentId.make("environment"),
166 + threadId: ThreadId.make(thread),
167 + },
168 +});
169 +
170 +async function renderActions(thread: string, cwd: string) {
171 + let renderer!: ReturnType<typeof create>;
172 + await act(async () => {
173 + renderer = create(createElement(MemoGitActionsControl, props(thread, cwd)));
174 + });
175 + renderers.push(renderer);
176 + return renderer;
177 +}
178 +
179 +async function clickQuickAction(renderer: ReturnType<typeof create>) {
180 + const button = renderer.root
181 + .findAllByType("button")
182 + .find((button) => button.props.onClick && !button.props.disabled);
183 + expect(button).toBeDefined();
184 + await act(async () => {
185 + button!.props.onClick({});
186 + });
187 +}
188 +
189 +beforeEach(() => {
190 + state.scopes = new Set([AuthSourceControlWriteScope]);
191 + state.primaryScopes = new Set([AuthSourceControlWriteScope]);
192 + state.actions = [];
193 + state.toasts = [];
194 +});
195 +
196 +afterEach(async () => {
197 + await act(async () => {
198 + for (const renderer of renderers.splice(0)) renderer.unmount();
199 + });
200 +});
201 +
202 +describe("Git action targets across thread navigation", () => {
203 + it("runs a retained PR toast in the thread that produced it", async () => {
204 + const renderer = await renderActions("first", "/first");
205 + await clickQuickAction(renderer);
206 + const toast = state.toasts.find((toast) => toast.actionProps)!;
207 + expect(toast).toBeDefined();
208 + await act(async () => {
209 + renderer.update(createElement(MemoGitActionsControl, props("second", "/second")));
210 + });
211 + await act(async () => {
212 + toast.actionProps!.onClick();
213 + });
214 + expect(state.actions.at(-1)).toMatchObject({
215 + scope: { cwd: "/first" },
216 + input: { threadId: "first", action: "commit_push_pr" },
217 + });
218 + });
219 +
220 + it("runs the memoized panel button in the current thread after navigation", async () => {
221 + const renderer = await renderActions("first", "/first");
222 + for (const [thread, cwd] of [
223 + ["first", "/first"],
224 + ["second", "/second"],
225 + ["first", "/first"],
226 + ] as const) {
227 + await act(async () => {
228 + renderer.update(createElement(MemoGitActionsControl, props(thread, cwd)));
229 + });
230 + await clickQuickAction(renderer);
231 + expect(state.actions.at(-1)).toMatchObject({ scope: { cwd }, input: { threadId: thread } });
232 + }
233 + });
234 +});
apps/web/src/components/GitActionsControl.test.ts
+4 -5
@@ -23,15 +23,14 @@ const state = vi.hoisted(() => ({
23
24 vi.mock("react", async (importOriginal) => ({
25 ...(await importOriginal<typeof import("react")>()),
26 - useCallback: (callback: unknown) => callback,
26 + useCallback: (callback: typeof state.run) => {
27 + if (callback?.constructor.name === "AsyncFunction") state.run = callback;
28 + return callback;
29 + },
30 useMemo: (factory: () => unknown) => factory(),
31 useState: (initial: unknown) => [typeof initial === "function" ? initial() : initial, () => {}],
32 useRef: (current: unknown) => ({ current }),
33 useEffect: () => {},
31 - useEffectEvent: (callback: typeof state.run) => {
32 - state.run = callback;
33 - return callback;
34 - },
34 }));
35 vi.mock("@effect/atom-react", () => ({
36 useAtomValue: (atom: unknown) => (atom === "vcs-state" ? { isRunning: false } : null),
apps/web/src/components/GitActionsControl.tsx
+20 -13
@@ -21,15 +21,7 @@ import type {
21 } from "@t3tools/contracts";
22 import { useNavigate } from "@tanstack/react-router";
23 import * as Option from "effect/Option";
24 -import {
25 - type MouseEvent,
26 - useCallback,
27 - useEffect,
28 - useEffectEvent,
29 - useMemo,
30 - useRef,
31 - useState,
32 -} from "react";
24 +import { type MouseEvent, useCallback, useEffect, useMemo, useRef, useState } from "react";
25 import { flushSync } from "react-dom";
26 import {
27 CheckIcon,
@@ -1062,7 +1054,6 @@ export default function GitActionsControl({
1054 );
1055 const vcsActionState = useAtomValue(vcsActionManager.stateAtom(sourceControlScope));
1056 const visibleInlineSuccess = inlineSuccess?.scopeKey === successScopeKey ? inlineSuccess : null;
1065 - let runGitActionWithToast: (input: RunGitActionWithToastInput) => Promise<void>;
1057
1058 useEffect(() => {
1059 if (!inlineSuccess) return;
@@ -1258,8 +1249,10 @@ export default function GitActionsControl({
1249 };
1250 }, [activeEnvironmentId, gitCwd, refreshVcsStatus]);
1251
1261 - runGitActionWithToast = useEffectEvent(
1262 - async ({
1252 + // React 19.2 leaves useEffectEvent stale inside the memoized details panel.
1253 + // Bind each render's actions to its checkout and thread, including retained toast actions.
1254 + const runGitActionWithToast = useCallback(
1255 + async function runGitActionWithToast({
1256 action,
1257 commitMessage,
1258 onConfirmed,
@@ -1267,7 +1260,7 @@ export default function GitActionsControl({
1260 statusOverride,
1261 featureBranch = false,
1262 filePaths,
1270 - }: RunGitActionWithToastInput) => {
1263 + }: RunGitActionWithToastInput) {
1264 if (
1265 activeEnvironmentId === null ||
1266 !readEnvironmentScope(activeEnvironmentId, AuthSourceControlWriteScope) ||
@@ -1415,6 +1408,20 @@ export default function GitActionsControl({
1408 });
1409 }
1410 },
1411 + [
1412 + activeDraftThread,
1413 + activeEnvironmentId,
1414 + activeServerThread,
1415 + gitStatusForActions,
1416 + isDefaultRef,
1417 + isLocalDraftThread,
1418 + isPanel,
1419 + openPrLink,
1420 + runImmediateGitAction,
1421 + successScopeKey,
1422 + syncThreadBranchAfterGitAction,
1423 + threadToastData,
1424 + ],
1425 );
1426
1427 const continuePendingDefaultBranchAction = () => {