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 23, 05:30 UTC
perf(web): Git actions control compiles without manual memoization (#20777)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 23:11 UTC
b38aa027dcb47717a55aafb1ef6a423b5194a50b
2 files changed
+335
-361
apps/web/src/components/GitActionsControl.test.ts
+71
-30
@@ -1,3 +1,4 @@
1
+// @vitest-environment jsdom
2
import {
3
AuthOrchestrationOperateScope,
4
AuthSourceControlWriteScope,
@@ -6,7 +7,7 @@ import {
7
} from "@t3tools/contracts";
8
import * as Cause from "effect/Cause";
9
import { AsyncResult } from "effect/reactivity";
9
-import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
10
+import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
11
12
const state = vi.hoisted(() => ({
13
scopes: new Set<string>(),
@@ -18,20 +19,8 @@ const state = vi.hoisted(() => ({
19
commits: 0,
20
metadataRequests: [] as { environmentId: string; branch: string }[],
21
afterGitAction: undefined as (() => void) | undefined,
21
- run: null as ((input: { action: "commit"; featureBranch?: boolean }) => Promise<void>) | null,
22
}));
23
24
-vi.mock("react", async (importOriginal) => ({
25
- ...(await importOriginal<typeof import("react")>()),
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: () => {},
34
-}));
24
vi.mock("@effect/atom-react", () => ({
25
useAtomValue: (atom: unknown) => (atom === "vcs-state" ? { isRunning: false } : null),
26
}));
@@ -48,7 +37,8 @@ vi.mock("~/state/session", () => ({
37
}));
38
vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: (command: unknown) => command }));
39
vi.mock("~/state/server", () => ({ serverEnvironment: { configValueAtom: () => null } }));
51
-vi.mock("~/state/sourceControl", () => ({ sourceControlEnvironment: {} }));
40
+vi.mock("~/state/sourceControl", () => ({ sourceControlEnvironment: { discovery: () => null } }));
41
+vi.mock("@tanstack/react-router", () => ({ useNavigate: () => () => {} }));
42
vi.mock("~/state/vcs", () => ({
43
vcsEnvironment: { status: () => null },
44
vcsActionManager: { stateAtom: () => "vcs-state" },
@@ -74,8 +64,9 @@ vi.mock("~/state/threads", () => ({
64
vi.mock("~/state/query", () => ({
65
useEnvironmentQuery: () => ({
66
data: {
67
+ sourceControlProviders: [],
68
isRepo: true,
78
- refName: "main",
69
+ refName: state.branch,
70
isDefaultRef: false,
71
hasPrimaryRemote: true,
72
hasWorkingTreeChanges: true,
@@ -171,18 +162,53 @@ vi.mock("./AnimatedHeight", () => ({ AnimatedHeight: "AnimatedHeight" }));
162
163
import GitActionsControl from "./GitActionsControl";
164
174
-function renderActions() {
175
- GitActionsControl({
165
+import { createElement } from "react";
166
+import { act, create, type ReactTestRenderer } from "react-test-renderer";
167
+
168
+vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
169
+
170
+let renderer: ReactTestRenderer | null = null;
171
+
172
+// Opens the commit dialog and returns its buttons' handlers from this render, so a test can
173
+// change grants afterwards and still click what the user saw.
174
+async function renderActions() {
175
+ const element = createElement(GitActionsControl, {
176
gitCwd: "/repo",
177
activeThreadRef: {
178
environmentId: EnvironmentId.make("environment"),
179
threadId: ThreadId.make("thread"),
180
},
181
});
182
- if (!state.run) throw new Error("Git action missing");
183
- return state.run;
182
+ await act(async () => {
183
+ if (renderer) renderer.update(element);
184
+ else renderer = create(element);
185
+ });
186
+ const root = renderer!.root;
187
+ const commitMenuItem = root.find(
188
+ (node) => String(node.type) === "MenuItemLabel" && node.props.children === "Commit",
189
+ ).parent!;
190
+ await act(async () => {
191
+ commitMenuItem.props.onClick();
192
+ });
193
+ const buttonHandler = (label: string): (() => void) =>
194
+ root.find((node) => String(node.type) === "Button" && node.props.children === label).props
195
+ .onClick;
196
+ const commit = buttonHandler("Commit");
197
+ const commitOnNewBranch = buttonHandler("Commit on new branch");
198
+ return async ({ featureBranch }: { action: "commit"; featureBranch?: boolean }) => {
199
+ await act(async () => {
200
+ (featureBranch ? commitOnNewBranch : commit)();
201
+ });
202
+ };
203
}
204
205
+afterEach(async () => {
206
+ await act(async () => {
207
+ renderer?.unmount();
208
+ });
209
+ renderer = null;
210
+});
211
+
212
describe("Git actions while thread details load", () => {
213
beforeEach(() => {
214
state.scopes = new Set([AuthSourceControlWriteScope]);
@@ -194,11 +220,12 @@ describe("Git actions while thread details load", () => {
220
state.commits = 0;
221
state.metadataRequests = [];
222
state.afterGitAction = undefined;
197
- state.run = null;
223
});
224
225
it("does not create a feature branch for a server thread without task permission", async () => {
201
- await renderActions()({ action: "commit", featureBranch: true });
226
+ await (
227
+ await renderActions()
228
+ )({ action: "commit", featureBranch: true });
229
230
expect(state.branch).toBe("main");
231
expect(state.commits).toBe(0);
@@ -208,7 +235,9 @@ describe("Git actions while thread details load", () => {
235
it("commits and synchronizes the server thread before details finish loading", async () => {
236
state.primaryScopes.clear();
237
state.scopes.add(AuthOrchestrationOperateScope);
211
- await renderActions()({ action: "commit", featureBranch: true });
238
+ await (
239
+ await renderActions()
240
+ )({ action: "commit", featureBranch: true });
241
242
expect(state.branch).toBe("feature");
243
expect(state.commits).toBe(1);
@@ -219,10 +248,12 @@ describe("Git actions while thread details load", () => {
248
it("synchronizes archived thread detail after its shell disappears", async () => {
249
state.scopes.add(AuthOrchestrationOperateScope);
250
state.detail = { branch: "main" };
222
- renderActions();
251
+ await renderActions();
252
state.shell = null;
253
225
- await renderActions()({ action: "commit", featureBranch: true });
254
+ await (
255
+ await renderActions()
256
+ )({ action: "commit", featureBranch: true });
257
258
expect(state.commits).toBe(1);
259
expect(state.branch).toBe("feature");
@@ -234,7 +265,9 @@ describe("Git actions while thread details load", () => {
265
state.shell = null;
266
state.detail = { branch: "main" };
267
237
- await renderActions()({ action: "commit", featureBranch: true });
268
+ await (
269
+ await renderActions()
270
+ )({ action: "commit", featureBranch: true });
271
272
expect(state.commits).toBe(0);
273
expect(state.detail.branch).toBe("main");
@@ -245,7 +278,9 @@ describe("Git actions while thread details load", () => {
278
state.scopes.add(AuthOrchestrationOperateScope);
279
state.detail = { branch: "feature" };
280
248
- await renderActions()({ action: "commit", featureBranch: true });
281
+ await (
282
+ await renderActions()
283
+ )({ action: "commit", featureBranch: true });
284
285
expect(state.commits).toBe(1);
286
expect(state.shell?.branch).toBe("feature");
@@ -253,7 +288,7 @@ describe("Git actions while thread details load", () => {
288
});
289
290
it("synchronizes a retained callback after the thread grant is gained", async () => {
256
- const run = renderActions();
291
+ const run = await renderActions();
292
state.scopes.add(AuthOrchestrationOperateScope);
293
await run({ action: "commit", featureBranch: true });
294
expect(state.commits).toBe(1);
@@ -269,7 +304,9 @@ describe("Git actions while thread details load", () => {
304
async (revokedScope, syncsThread) => {
305
state.scopes.add(AuthOrchestrationOperateScope);
306
state.afterGitAction = () => state.scopes.delete(revokedScope);
272
- await renderActions()({ action: "commit", featureBranch: true });
307
+ await (
308
+ await renderActions()
309
+ )({ action: "commit", featureBranch: true });
310
expect(state.commits).toBe(1);
311
expect(state.branch).toBe("feature");
312
expect(state.shell?.branch).toBe(syncsThread ? "feature" : "main");
@@ -278,7 +315,9 @@ describe("Git actions while thread details load", () => {
315
);
316
317
it("keeps ordinary commits available while details load", async () => {
281
- await renderActions()({ action: "commit" });
318
+ await (
319
+ await renderActions()
320
+ )({ action: "commit" });
321
322
expect(state.commits).toBe(1);
323
expect(state.branch).toBe("main");
@@ -287,7 +326,9 @@ describe("Git actions while thread details load", () => {
326
it("keeps feature-branch commits available for a local draft", async () => {
327
state.shell = null;
328
state.draft = { branch: "main", worktreePath: null, envMode: "local" };
290
- await renderActions()({ action: "commit", featureBranch: true });
329
+ await (
330
+ await renderActions()
331
+ )({ action: "commit", featureBranch: true });
332
333
expect(state.commits).toBe(1);
334
expect(state.draft.branch).toBe("feature");
apps/web/src/components/GitActionsControl.tsx
+264
-331
@@ -21,7 +21,7 @@ import type {
21
} from "@t3tools/contracts";
22
import { useNavigate } from "@tanstack/react-router";
23
import * as Option from "effect/Option";
24
-import { type MouseEvent, useCallback, useEffect, useMemo, useRef, useState } from "react";
24
+import { type MouseEvent, useEffect, useEffectEvent, useRef, useState } from "react";
25
import { flushSync } from "react-dom";
26
import {
27
CheckIcon,
@@ -481,48 +481,38 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
481
const [publishResult, setPublishResult] = useState<SourceControlPublishRepositoryResult | null>(
482
null,
483
);
484
- const sourceControlScope = useMemo(
485
- () => ({
486
- environmentId: props.environmentId,
487
- cwd: props.gitCwd,
488
- }),
489
- [props.environmentId, props.gitCwd],
490
- );
484
+ const sourceControlScope = {
485
+ environmentId: props.environmentId,
486
+ cwd: props.gitCwd,
487
+ };
488
const publishRepositoryAction = useSourceControlPublishRepositoryAction(sourceControlScope);
492
- const publishAccountByProvider = useMemo(() => {
493
- const accounts = new Map<string, string | null>();
494
- for (const provider of sourceControlDiscovery.data?.sourceControlProviders ?? []) {
495
- accounts.set(provider.kind, Option.getOrNull(provider.auth.account));
496
- }
497
- return accounts;
498
- }, [sourceControlDiscovery.data]);
499
- const publishProviderReadiness = useMemo(() => {
500
- const sourceControlProviders = sourceControlDiscovery.data?.sourceControlProviders ?? [];
501
- const readiness = new Map(
502
- PUBLISH_PROVIDER_OPTIONS.map((option) => [
503
- option.value,
504
- getPublishProviderReadiness({ provider: option.value, sourceControlProviders }),
505
- ]),
506
- );
507
- return (provider: SourceControlProviderKind) =>
508
- readiness.get(provider) ?? { ready: false, hint: null };
509
- }, [sourceControlDiscovery.data]);
510
- const hasReadyPublishProvider = useMemo(
511
- () => PUBLISH_PROVIDER_OPTIONS.some((option) => publishProviderReadiness(option.value).ready),
512
- [publishProviderReadiness],
513
- );
514
- const sortedPublishProviderOptions = useMemo(
515
- () =>
516
- PUBLISH_PROVIDER_OPTIONS.toSorted((left, right) => {
517
- const leftReady = publishProviderReadiness(left.value).ready;
518
- const rightReady = publishProviderReadiness(right.value).ready;
519
- if (leftReady !== rightReady) {
520
- return leftReady ? -1 : 1;
521
- }
522
- return left.label.localeCompare(right.label);
489
+ const publishAccountByProvider = new Map<string, string | null>();
490
+ for (const provider of sourceControlDiscovery.data?.sourceControlProviders ?? []) {
491
+ publishAccountByProvider.set(provider.kind, Option.getOrNull(provider.auth.account));
492
+ }
493
+ const publishSourceControlProviders = sourceControlDiscovery.data?.sourceControlProviders ?? [];
494
+ const publishReadinessByProvider = new Map(
495
+ PUBLISH_PROVIDER_OPTIONS.map((option) => [
496
+ option.value,
497
+ getPublishProviderReadiness({
498
+ provider: option.value,
499
+ sourceControlProviders: publishSourceControlProviders,
500
}),
524
- [publishProviderReadiness],
501
+ ]),
502
+ );
503
+ const publishProviderReadiness = (provider: SourceControlProviderKind) =>
504
+ publishReadinessByProvider.get(provider) ?? { ready: false, hint: null };
505
+ const hasReadyPublishProvider = PUBLISH_PROVIDER_OPTIONS.some(
506
+ (option) => publishProviderReadiness(option.value).ready,
507
);
508
+ const sortedPublishProviderOptions = PUBLISH_PROVIDER_OPTIONS.toSorted((left, right) => {
509
+ const leftReady = publishProviderReadiness(left.value).ready;
510
+ const rightReady = publishProviderReadiness(right.value).ready;
511
+ if (leftReady !== rightReady) {
512
+ return leftReady ? -1 : 1;
513
+ }
514
+ return left.label.localeCompare(right.label);
515
+ });
516
const firstReadyPublishProvider = sortedPublishProviderOptions.find(
517
(option) => publishProviderReadiness(option.value).ready,
518
)?.value;
@@ -553,22 +543,17 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
543
null,
544
] as const;
545
556
- const canSubmitPublishRepository = useMemo(() => {
557
- if (!publishRepositoryAction.isAllowed || !selectedPublishProviderReadiness.ready) return false;
558
- if (publishRepositoryAction.isPending) return false;
559
- const repositoryParts = publishRepository.trim().split("/");
560
- const owner = repositoryParts[0]?.trim() ?? "";
561
- const rest = repositoryParts.slice(1);
562
- const name = rest.join("/").trim();
563
- return owner.length > 0 && name.length > 0;
564
- }, [
565
- publishRepository,
566
- publishRepositoryAction.isAllowed,
567
- publishRepositoryAction.isPending,
568
- selectedPublishProviderReadiness,
569
- ]);
570
-
571
- const submitPublishRepository = useCallback(() => {
546
+ const publishRepositoryParts = publishRepository.trim().split("/");
547
+ const publishRepositoryOwner = publishRepositoryParts[0]?.trim() ?? "";
548
+ const publishRepositoryName = publishRepositoryParts.slice(1).join("/").trim();
549
+ const canSubmitPublishRepository =
550
+ publishRepositoryAction.isAllowed &&
551
+ selectedPublishProviderReadiness.ready &&
552
+ !publishRepositoryAction.isPending &&
553
+ publishRepositoryOwner.length > 0 &&
554
+ publishRepositoryName.length > 0;
555
+
556
+ const submitPublishRepository = () => {
557
if (!canSubmitPublishRepository) {
558
return;
559
}
@@ -597,41 +582,28 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
582
setPublishWizardStep(2);
583
});
584
})();
600
- }, [
601
- canSubmitPublishRepository,
602
- props.environmentId,
603
- props.gitCwd,
604
- publishProtocol,
605
- publishProvider,
606
- publishRemoteName,
607
- publishRepository,
608
- publishRepositoryAction,
609
- publishVisibility,
610
- ]);
585
+ };
586
612
- const resetState = useCallback(() => {
587
+ const resetState = () => {
588
setPublishRemoteName("origin");
589
setPublishRepositoryOverride(null);
590
setPublishWizardStep(0);
591
setPublishAdvancedOpen(false);
592
setPublishError(null);
593
setPublishResult(null);
619
- }, []);
594
+ };
595
621
- const handleOpenChange = useCallback(
622
- (open: boolean) => {
623
- props.onOpenChange(open);
624
- if (!open) {
625
- resetState();
626
- }
627
- },
628
- [props, resetState],
629
- );
596
+ const handleOpenChange = (open: boolean) => {
597
+ props.onOpenChange(open);
598
+ if (!open) {
599
+ resetState();
600
+ }
601
+ };
602
631
- const openSourceControlSettings = useCallback(() => {
603
+ const openSourceControlSettings = () => {
604
handleOpenChange(false);
605
void navigate({ to: "/settings/source-control" });
634
- }, [handleOpenChange, navigate]);
606
+ };
607
608
return (
609
<Dialog open={props.open} onOpenChange={handleOpenChange}>
@@ -1009,10 +981,7 @@ export default function GitActionsControl({
981
activeEnvironmentId,
982
serverConfig?.availableEditors ?? [],
983
);
1012
- const threadToastData = useMemo(
1013
- () => (activeThreadRef ? { threadRef: activeThreadRef } : undefined),
1014
- [activeThreadRef],
1015
- );
984
+ const threadToastData = activeThreadRef ? { threadRef: activeThreadRef } : undefined;
985
const activeServerThreadShell = useThreadShell(activeThreadRef);
986
const openPrLink = useOpenPrLink(activeThreadRef ?? undefined);
987
const activeDraftThread = useComposerDraftStore((store) =>
@@ -1038,10 +1007,7 @@ export default function GitActionsControl({
1007
const [inlineSuccess, setInlineSuccess] = useState<InlineGitActionSuccess | null>(null);
1008
const [pendingDefaultBranchAction, setPendingDefaultBranchAction] =
1009
useState<PendingDefaultBranchAction | null>(null);
1041
- const sourceControlScope = useMemo(
1042
- () => ({ environmentId: activeEnvironmentId, cwd: gitCwd }),
1043
- [activeEnvironmentId, gitCwd],
1044
- );
1010
+ const sourceControlScope = { environmentId: activeEnvironmentId, cwd: gitCwd };
1011
const vcsActionState = useAtomValue(vcsActionManager.stateAtom(sourceControlScope));
1012
const visibleInlineSuccess = inlineSuccess?.scopeKey === successScopeKey ? inlineSuccess : null;
1013
@@ -1053,65 +1019,55 @@ export default function GitActionsControl({
1019
return () => window.clearTimeout(timeoutId);
1020
}, [inlineSuccess]);
1021
1056
- const persistThreadBranchSync = useCallback(
1057
- (branch: string | null, manualSelection = false) => {
1058
- if (!activeThreadRef) {
1022
+ const persistThreadBranchSync = (branch: string | null, manualSelection = false) => {
1023
+ if (!activeThreadRef) {
1024
+ return;
1025
+ }
1026
+
1027
+ if (activeServerThread) {
1028
+ if (
1029
+ !readEnvironmentScope(activeThreadRef.environmentId, AuthOrchestrationOperateScope) ||
1030
+ activeServerThread.branch === branch
1031
+ ) {
1032
return;
1033
}
1034
1062
- if (activeServerThread) {
1063
- if (
1064
- !readEnvironmentScope(activeThreadRef.environmentId, AuthOrchestrationOperateScope) ||
1065
- activeServerThread.branch === branch
1066
- ) {
1067
- return;
1068
- }
1069
-
1070
- void updateThreadMetadata({
1071
- environmentId: activeThreadRef.environmentId,
1072
- input: {
1073
- threadId: activeThreadRef.threadId,
1074
- ...resolveThreadBranchMetadataPatch(branch, activeServerThread.branch),
1075
- },
1076
- });
1035
+ void updateThreadMetadata({
1036
+ environmentId: activeThreadRef.environmentId,
1037
+ input: {
1038
+ threadId: activeThreadRef.threadId,
1039
+ ...resolveThreadBranchMetadataPatch(branch, activeServerThread.branch),
1040
+ },
1041
+ });
1042
1078
- return;
1079
- }
1043
+ return;
1044
+ }
1045
1081
- if (!activeDraftThread || activeDraftThread.branch === branch) {
1082
- return;
1083
- }
1046
+ if (!activeDraftThread || activeDraftThread.branch === branch) {
1047
+ return;
1048
+ }
1049
1085
- setDraftThreadContext(draftId ?? activeThreadRef, {
1086
- branch,
1087
- worktreePath: activeDraftThread.worktreePath,
1088
- environmentSelection: manualSelection
1089
- ? "manual"
1090
- : (activeDraftThread.environmentSelection ??
1091
- (activeDraftThread.branch ? "manual" : "auto")),
1092
- });
1093
- },
1094
- [
1095
- activeDraftThread,
1096
- activeServerThread,
1097
- activeThreadRef,
1098
- draftId,
1099
- setDraftThreadContext,
1100
- updateThreadMetadata,
1101
- ],
1102
- );
1050
+ setDraftThreadContext(draftId ?? activeThreadRef, {
1051
+ branch,
1052
+ worktreePath: activeDraftThread.worktreePath,
1053
+ environmentSelection: manualSelection
1054
+ ? "manual"
1055
+ : (activeDraftThread.environmentSelection ??
1056
+ (activeDraftThread.branch ? "manual" : "auto")),
1057
+ });
1058
+ };
1059
+ const persistLiveThreadBranch = useEffectEvent((branch: string | null) => {
1060
+ persistThreadBranchSync(branch);
1061
+ });
1062
1104
- const syncThreadBranchAfterGitAction = useCallback(
1105
- (result: GitRunStackedActionResult) => {
1106
- const branchUpdate = resolveThreadBranchUpdate(result);
1107
- if (!branchUpdate) {
1108
- return;
1109
- }
1063
+ const syncThreadBranchAfterGitAction = (result: GitRunStackedActionResult) => {
1064
+ const branchUpdate = resolveThreadBranchUpdate(result);
1065
+ if (!branchUpdate) {
1066
+ return;
1067
+ }
1068
1111
- persistThreadBranchSync(branchUpdate.branch, true);
1112
- },
1113
- [persistThreadBranchSync],
1114
- );
1069
+ persistThreadBranchSync(branchUpdate.branch, true);
1070
+ };
1071
1072
const gitStatusQuery = useEnvironmentQuery(
1073
activeEnvironmentId !== null && gitCwd !== null
@@ -1125,10 +1081,7 @@ export default function GitActionsControl({
1081
reportFailure: false,
1082
});
1083
const { data: gitStatus, error: gitStatusError } = gitStatusQuery;
1128
- const sourceControlPresentation = useMemo(
1129
- () => getSourceControlPresentation(gitStatus?.sourceControlProvider),
1130
- [gitStatus?.sourceControlProvider],
1131
- );
1084
+ const sourceControlPresentation = getSourceControlPresentation(gitStatus?.sourceControlProvider);
1085
const changeRequestTerminology = sourceControlPresentation.terminology;
1086
const SourceControlIcon = sourceControlPresentation.Icon;
1087
const isRepo = gitStatus?.isRepo ?? true;
@@ -1166,28 +1119,27 @@ export default function GitActionsControl({
1119
return;
1120
}
1121
1169
- persistThreadBranchSync(branchUpdate.branch);
1122
+ persistLiveThreadBranch(branchUpdate.branch);
1123
}, [
1124
activeServerThread,
1125
activeDraftThread?.branch,
1126
gitStatusForActions,
1127
isGitActionRunning,
1128
isSelectingWorktreeBase,
1176
- persistThreadBranchSync,
1129
]);
1130
1179
- const isDefaultRef = useMemo(() => {
1180
- return gitStatusForActions?.isDefaultRef ?? false;
1181
- }, [gitStatusForActions?.isDefaultRef]);
1131
+ const isDefaultRef = gitStatusForActions?.isDefaultRef ?? false;
1132
1183
- const gitActionMenuItems = useMemo(
1184
- () => buildMenuItems(gitStatusForActions, isGitActionRunning, hasPrimaryRemote),
1185
- [gitStatusForActions, hasPrimaryRemote, isGitActionRunning],
1133
+ const gitActionMenuItems = buildMenuItems(
1134
+ gitStatusForActions,
1135
+ isGitActionRunning,
1136
+ hasPrimaryRemote,
1137
);
1187
- const quickAction = useMemo(
1188
- () =>
1189
- resolveQuickAction(gitStatusForActions, isGitActionRunning, isDefaultRef, hasPrimaryRemote),
1190
- [gitStatusForActions, hasPrimaryRemote, isDefaultRef, isGitActionRunning],
1138
+ const quickAction = resolveQuickAction(
1139
+ gitStatusForActions,
1140
+ isGitActionRunning,
1141
+ isDefaultRef,
1142
+ hasPrimaryRemote,
1143
);
1144
const quickActionDisabledReason = !canWriteSourceControl
1145
? "This connection cannot change source control."
@@ -1239,176 +1191,160 @@ export default function GitActionsControl({
1191
1192
// React 19.2 leaves useEffectEvent stale inside the memoized details panel.
1193
// Bind each render's actions to its checkout and thread, including retained toast actions.
1242
- const runGitActionWithToast = useCallback(
1243
- async function runGitActionWithToast({
1244
- action,
1245
- commitMessage,
1246
- onConfirmed,
1247
- skipDefaultBranchPrompt = false,
1248
- statusOverride,
1249
- featureBranch = false,
1250
- filePaths,
1251
- }: RunGitActionWithToastInput) {
1252
- if (
1253
- activeEnvironmentId === null ||
1254
- !readEnvironmentScope(activeEnvironmentId, AuthSourceControlWriteScope) ||
1255
- (featureBranch &&
1256
- !isLocalDraftThread &&
1257
- !readEnvironmentScope(activeEnvironmentId, AuthOrchestrationOperateScope))
1258
- )
1259
- return;
1260
- const actionStatus = statusOverride ?? gitStatusForActions;
1261
- const actionBranch = actionStatus?.refName ?? null;
1262
- const actionIsDefaultBranch = featureBranch ? false : isDefaultRef;
1263
- const actionCanCommit =
1264
- action === "commit" || action === "commit_push" || action === "commit_push_pr";
1265
- const includesCommit =
1266
- actionCanCommit &&
1267
- (action === "commit" || !!actionStatus?.hasWorkingTreeChanges || featureBranch);
1194
+ async function runGitActionWithToast({
1195
+ action,
1196
+ commitMessage,
1197
+ onConfirmed,
1198
+ skipDefaultBranchPrompt = false,
1199
+ statusOverride,
1200
+ featureBranch = false,
1201
+ filePaths,
1202
+ }: RunGitActionWithToastInput) {
1203
+ if (
1204
+ activeEnvironmentId === null ||
1205
+ !readEnvironmentScope(activeEnvironmentId, AuthSourceControlWriteScope) ||
1206
+ (featureBranch &&
1207
+ !isLocalDraftThread &&
1208
+ !readEnvironmentScope(activeEnvironmentId, AuthOrchestrationOperateScope))
1209
+ )
1210
+ return;
1211
+ const actionStatus = statusOverride ?? gitStatusForActions;
1212
+ const actionBranch = actionStatus?.refName ?? null;
1213
+ const actionIsDefaultBranch = featureBranch ? false : isDefaultRef;
1214
+ const actionCanCommit =
1215
+ action === "commit" || action === "commit_push" || action === "commit_push_pr";
1216
+ const includesCommit =
1217
+ actionCanCommit &&
1218
+ (action === "commit" || !!actionStatus?.hasWorkingTreeChanges || featureBranch);
1219
+ if (
1220
+ !skipDefaultBranchPrompt &&
1221
+ requiresDefaultBranchConfirmation(action, actionIsDefaultBranch) &&
1222
+ actionBranch
1223
+ ) {
1224
if (
1269
- !skipDefaultBranchPrompt &&
1270
- requiresDefaultBranchConfirmation(action, actionIsDefaultBranch) &&
1271
- actionBranch
1225
+ action !== "push" &&
1226
+ action !== "create_pr" &&
1227
+ action !== "commit_push" &&
1228
+ action !== "commit_push_pr"
1229
) {
1273
- if (
1274
- action !== "push" &&
1275
- action !== "create_pr" &&
1276
- action !== "commit_push" &&
1277
- action !== "commit_push_pr"
1278
- ) {
1279
- return;
1280
- }
1281
- setPendingDefaultBranchAction({
1282
- action,
1283
- branchName: actionBranch,
1284
- includesCommit,
1285
- ...(commitMessage ? { commitMessage } : {}),
1286
- ...(onConfirmed ? { onConfirmed } : {}),
1287
- ...(filePaths ? { filePaths } : {}),
1288
- });
1230
return;
1231
}
1291
- onConfirmed?.();
1292
- setInlineSuccess(null);
1293
-
1294
- const scopedToastData = threadToastData ? { ...threadToastData } : undefined;
1295
- const actionId = randomUUID();
1296
-
1297
- const result = await runImmediateGitAction.run({
1298
- actionId,
1232
+ setPendingDefaultBranchAction({
1233
action,
1234
+ branchName: actionBranch,
1235
+ includesCommit,
1236
...(commitMessage ? { commitMessage } : {}),
1301
- ...(featureBranch ? { featureBranch } : {}),
1237
+ ...(onConfirmed ? { onConfirmed } : {}),
1238
...(filePaths ? { filePaths } : {}),
1303
- ...(activeServerThread ? { threadId: activeServerThread.id } : {}),
1304
- ...(activeDraftThread ? { projectId: activeDraftThread.projectId } : {}),
1239
});
1240
+ return;
1241
+ }
1242
+ onConfirmed?.();
1243
+ setInlineSuccess(null);
1244
1307
- if (result._tag === "Failure") {
1308
- if (isAtomCommandInterrupted(result)) {
1309
- return;
1310
- }
1245
+ const scopedToastData = threadToastData ? { ...threadToastData } : undefined;
1246
+ const actionId = randomUUID();
1247
1312
- const error = squashAtomCommandFailure(result);
1313
- const errorToastTiming = resolveGitActionResultToastTiming("error");
1314
- toastManager.add(
1315
- stackedThreadToast({
1316
- type: "error",
1317
- title: "Action failed",
1318
- description: error instanceof Error ? error.message : "An error occurred.",
1319
- timeout: errorToastTiming.timeout,
1320
- ...(scopedToastData !== undefined ? { data: scopedToastData } : {}),
1321
- }),
1322
- );
1323
- return;
1324
- }
1248
+ const result = await runImmediateGitAction.run({
1249
+ actionId,
1250
+ action,
1251
+ ...(commitMessage ? { commitMessage } : {}),
1252
+ ...(featureBranch ? { featureBranch } : {}),
1253
+ ...(filePaths ? { filePaths } : {}),
1254
+ ...(activeServerThread ? { threadId: activeServerThread.id } : {}),
1255
+ ...(activeDraftThread ? { projectId: activeDraftThread.projectId } : {}),
1256
+ });
1257
1326
- const actionResult = result.value;
1327
- syncThreadBranchAfterGitAction(actionResult);
1328
- if (isPanel) {
1329
- setInlineSuccess({
1330
- title: actionResult.toast.title,
1331
- description: actionResult.toast.description ?? null,
1332
- scopeKey: successScopeKey,
1333
- });
1258
+ if (result._tag === "Failure") {
1259
+ if (isAtomCommandInterrupted(result)) {
1260
return;
1261
}
1336
- let resultToastId: GitActionToastId | null = null;
1337
- const closeResultToast = () => {
1338
- if (resultToastId !== null) {
1339
- toastManager.close(resultToastId);
1340
- }
1341
- };
1262
1343
- const toastCta = actionResult.toast.cta;
1344
- let toastActionProps: {
1345
- children: string;
1346
- onClick: (event: MouseEvent<HTMLButtonElement>) => void;
1347
- } | null = null;
1348
- if (toastCta.kind === "run_action") {
1349
- toastActionProps = {
1350
- children: toastCta.label,
1351
- onClick: () => {
1352
- closeResultToast();
1353
- void runGitActionWithToast({
1354
- action: toastCta.action.kind,
1355
- });
1356
- },
1357
- };
1358
- } else if (toastCta.kind === "open_pr") {
1359
- toastActionProps = {
1360
- children: toastCta.label,
1361
- onClick: (event) => {
1362
- closeResultToast();
1363
- openPrLink(event, toastCta.url);
1364
- },
1365
- };
1263
+ const error = squashAtomCommandFailure(result);
1264
+ const errorToastTiming = resolveGitActionResultToastTiming("error");
1265
+ toastManager.add(
1266
+ stackedThreadToast({
1267
+ type: "error",
1268
+ title: "Action failed",
1269
+ description: error instanceof Error ? error.message : "An error occurred.",
1270
+ timeout: errorToastTiming.timeout,
1271
+ ...(scopedToastData !== undefined ? { data: scopedToastData } : {}),
1272
+ }),
1273
+ );
1274
+ return;
1275
+ }
1276
+
1277
+ const actionResult = result.value;
1278
+ syncThreadBranchAfterGitAction(actionResult);
1279
+ if (isPanel) {
1280
+ setInlineSuccess({
1281
+ title: actionResult.toast.title,
1282
+ description: actionResult.toast.description ?? null,
1283
+ scopeKey: successScopeKey,
1284
+ });
1285
+ return;
1286
+ }
1287
+ let resultToastId: GitActionToastId | null = null;
1288
+ const closeResultToast = () => {
1289
+ if (resultToastId !== null) {
1290
+ toastManager.close(resultToastId);
1291
}
1292
+ };
1293
1368
- const successToastTiming = resolveGitActionResultToastTiming("success");
1369
- const successToastData = {
1370
- ...scopedToastData,
1371
- ...(successToastTiming.dismissAfterVisibleMs !== null
1372
- ? { dismissAfterVisibleMs: successToastTiming.dismissAfterVisibleMs }
1373
- : {}),
1294
+ const toastCta = actionResult.toast.cta;
1295
+ let toastActionProps: {
1296
+ children: string;
1297
+ onClick: (event: MouseEvent<HTMLButtonElement>) => void;
1298
+ } | null = null;
1299
+ if (toastCta.kind === "run_action") {
1300
+ toastActionProps = {
1301
+ children: toastCta.label,
1302
+ onClick: () => {
1303
+ closeResultToast();
1304
+ void runGitActionWithToast({
1305
+ action: toastCta.action.kind,
1306
+ });
1307
+ },
1308
};
1309
+ } else if (toastCta.kind === "open_pr") {
1310
+ toastActionProps = {
1311
+ children: toastCta.label,
1312
+ onClick: (event) => {
1313
+ closeResultToast();
1314
+ openPrLink(event, toastCta.url);
1315
+ },
1316
+ };
1317
+ }
1318
1376
- if (toastActionProps) {
1377
- resultToastId = toastManager.add(
1378
- stackedThreadToast({
1379
- type: "success",
1380
- title: actionResult.toast.title,
1381
- description: actionResult.toast.description,
1382
- timeout: successToastTiming.timeout,
1383
- actionProps: toastActionProps,
1384
- data: successToastData,
1385
- }),
1386
- );
1387
- } else {
1388
- resultToastId = toastManager.add({
1319
+ const successToastTiming = resolveGitActionResultToastTiming("success");
1320
+ const successToastData = {
1321
+ ...scopedToastData,
1322
+ ...(successToastTiming.dismissAfterVisibleMs !== null
1323
+ ? { dismissAfterVisibleMs: successToastTiming.dismissAfterVisibleMs }
1324
+ : {}),
1325
+ };
1326
+
1327
+ if (toastActionProps) {
1328
+ resultToastId = toastManager.add(
1329
+ stackedThreadToast({
1330
type: "success",
1331
title: actionResult.toast.title,
1332
description: actionResult.toast.description,
1333
timeout: successToastTiming.timeout,
1334
+ actionProps: toastActionProps,
1335
data: successToastData,
1394
- });
1395
- }
1396
- },
1397
- [
1398
- activeDraftThread,
1399
- activeEnvironmentId,
1400
- activeServerThread,
1401
- gitStatusForActions,
1402
- isDefaultRef,
1403
- isLocalDraftThread,
1404
- isPanel,
1405
- openPrLink,
1406
- runImmediateGitAction,
1407
- successScopeKey,
1408
- syncThreadBranchAfterGitAction,
1409
- threadToastData,
1410
- ],
1411
- );
1336
+ }),
1337
+ );
1338
+ } else {
1339
+ resultToastId = toastManager.add({
1340
+ type: "success",
1341
+ title: actionResult.toast.title,
1342
+ description: actionResult.toast.description,
1343
+ timeout: successToastTiming.timeout,
1344
+ data: successToastData,
1345
+ });
1346
+ }
1347
+ }
1348
1349
const continuePendingDefaultBranchAction = () => {
1350
if (!pendingDefaultBranchAction) return;
@@ -1424,7 +1360,7 @@ export default function GitActionsControl({
1360
};
1361
1362
const checkoutFeatureBranchAndContinuePendingAction = () => {
1427
- if (!canChangeThreadBranch || !pendingDefaultBranchAction) return;
1363
+ if (!pendingDefaultBranchAction) return;
1364
const { action, commitMessage, onConfirmed, filePaths } = pendingDefaultBranchAction;
1365
setPendingDefaultBranchAction(null);
1366
void runGitActionWithToast({
@@ -1438,7 +1374,7 @@ export default function GitActionsControl({
1374
};
1375
1376
const runDialogActionOnNewBranch = () => {
1441
- if (!canChangeThreadBranch || !isCommitDialogOpen) return;
1377
+ if (!isCommitDialogOpen) return;
1378
const commitMessage = dialogCommitMessage.trim();
1379
1380
setIsCommitDialogOpen(false);
@@ -1551,35 +1487,32 @@ export default function GitActionsControl({
1487
});
1488
};
1489
1554
- const openChangedFileInEditor = useCallback(
1555
- (filePath: string) => {
1556
- if (!gitCwd) {
1557
- toastManager.add({
1558
- type: "error",
1559
- title: "Editor opening is unavailable.",
1560
- data: threadToastData,
1561
- });
1490
+ const openChangedFileInEditor = (filePath: string) => {
1491
+ if (!gitCwd) {
1492
+ toastManager.add({
1493
+ type: "error",
1494
+ title: "Editor opening is unavailable.",
1495
+ data: threadToastData,
1496
+ });
1497
+ return;
1498
+ }
1499
+ const target = resolvePathLinkTarget(filePath, gitCwd);
1500
+ void (async () => {
1501
+ const result = await openInPreferredEditor(target);
1502
+ if (result._tag === "Success" || isAtomCommandInterrupted(result)) {
1503
return;
1504
}
1564
- const target = resolvePathLinkTarget(filePath, gitCwd);
1565
- void (async () => {
1566
- const result = await openInPreferredEditor(target);
1567
- if (result._tag === "Success" || isAtomCommandInterrupted(result)) {
1568
- return;
1569
- }
1570
- const error = squashAtomCommandFailure(result);
1571
- toastManager.add(
1572
- stackedThreadToast({
1573
- type: "error",
1574
- title: "Unable to open file",
1575
- description: error instanceof Error ? error.message : "An error occurred.",
1576
- ...(threadToastData !== undefined ? { data: threadToastData } : {}),
1577
- }),
1578
- );
1579
- })();
1580
- },
1581
- [gitCwd, openInPreferredEditor, threadToastData],
1582
- );
1505
+ const error = squashAtomCommandFailure(result);
1506
+ toastManager.add(
1507
+ stackedThreadToast({
1508
+ type: "error",
1509
+ title: "Unable to open file",
1510
+ description: error instanceof Error ? error.message : "An error occurred.",
1511
+ ...(threadToastData !== undefined ? { data: threadToastData } : {}),
1512
+ }),
1513
+ );
1514
+ })();
1515
+ };
1516
1517
const canPublishRepository =
1518
canWriteSourceControl && isRepo && gitStatusForActions !== null && !hasPrimaryRemote;