The best way to control Claude Code, Codex and more from any computer or phone
fix(web): keep pending pull request actions scoped to each request (#29005)
Yash Singh committed
Nov 1, 2026 at 21:22 UTC
4a5251b1c4b867ad2d89bf59d7a062ca8c40f2a6
2 files changed
+91
-7
apps/web/src/components/pullRequest/usePullRequestActions.browser.test.tsx
new
+74
@@ -0,0 +1,74 @@
1
+import { EnvironmentId, ProjectId, type PullRequestRef } from "@t3tools/contracts";
2
+import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
3
+import { expect, it, vi } from "vite-plus/test";
4
+import { userEvent } from "vite-plus/test/browser";
5
+
6
+import { act, render } from "../../../test/render";
7
+import { usePullRequestActionRunner } from "./usePullRequestActions";
8
+
9
+const state = vi.hoisted(() => ({ runAction: vi.fn() }));
10
+vi.mock(import("~/state/use-atom-command"), () => ({
11
+ useAtomCommand: (() => state.runAction) as never,
12
+}));
13
+
14
+function deferred<T>() {
15
+ let resolve!: (value: T) => void;
16
+ const promise = new Promise<T>((done) => {
17
+ resolve = done;
18
+ });
19
+ return { promise, resolve };
20
+}
21
+
22
+function MergeButton({ reference }: { reference: PullRequestRef }) {
23
+ const { actionPending, perform } = usePullRequestActionRunner({
24
+ environmentId: EnvironmentId.make("environment"),
25
+ reference,
26
+ terminology: sourceControlClients.get(undefined).changeRequest,
27
+ });
28
+ return (
29
+ <button type="button" disabled={actionPending} onClick={() => void perform("merge")}>
30
+ {actionPending ? "Merging..." : "Merge"}
31
+ </button>
32
+ );
33
+}
34
+
35
+it("keeps pending merges with their pull request when navigating between threads", async () => {
36
+ const first: PullRequestRef = {
37
+ projectId: ProjectId.make("project"),
38
+ repository: "owner/repo",
39
+ number: 1,
40
+ };
41
+ const second = { ...first, number: 2 };
42
+ const firstResult = deferred<{ _tag: "Success"; value: void }>();
43
+ const secondResult = deferred<{ _tag: "Success"; value: void }>();
44
+ state.runAction
45
+ .mockReset()
46
+ .mockReturnValueOnce(firstResult.promise)
47
+ .mockReturnValueOnce(secondResult.promise);
48
+ await using screen = await render(<MergeButton reference={first} />);
49
+ const button = screen.getByRole("button");
50
+
51
+ await userEvent.click(button);
52
+ await expect.element(button).toHaveTextContent("Merging...");
53
+ await screen.rerender(<MergeButton reference={second} />);
54
+ await expect.element(button).toHaveTextContent("Merge");
55
+ await expect.element(button).toBeEnabled();
56
+ await userEvent.click(button);
57
+ expect(state.runAction).toHaveBeenCalledTimes(2);
58
+
59
+ await screen.rerender(<MergeButton reference={first} />);
60
+ await expect.element(button).toHaveTextContent("Merging...");
61
+ await expect.element(button).toBeDisabled();
62
+ await act(async () => {
63
+ firstResult.resolve({ _tag: "Success", value: undefined });
64
+ await firstResult.promise;
65
+ });
66
+ await expect.element(button).toHaveTextContent("Merge");
67
+ await screen.rerender(<MergeButton reference={second} />);
68
+ await expect.element(button).toHaveTextContent("Merging...");
69
+ await act(async () => {
70
+ secondResult.resolve({ _tag: "Success", value: undefined });
71
+ await secondResult.promise;
72
+ });
73
+ await expect.element(button).toHaveTextContent("Merge");
74
+});
apps/web/src/components/pullRequest/usePullRequestActions.ts
+17
-7
@@ -140,13 +140,23 @@ export function usePullRequestActionRunner({
140
const runAction = useAtomCommand(pullRequestEnvironment.runAction, {
141
reportFailure: false,
142
});
143
- const [actionPending, setActionPending] = useState(false);
144
- const pendingRef = useRef(false);
143
+ const pendingRef = useRef(new Set<string>());
144
+ const [pendingKeys, setPendingKeys] = useState<ReadonlySet<string>>(() => new Set());
145
+ const actionKey =
146
+ reference === null
147
+ ? null
148
+ : JSON.stringify([
149
+ environmentId,
150
+ reference.host ?? null,
151
+ reference.repository,
152
+ reference.number,
153
+ ]);
154
+ const actionPending = actionKey !== null && pendingKeys.has(actionKey);
155
156
const perform = async (action: PullRequestAction, method?: PullRequestMergeMethod) => {
147
- if (pendingRef.current || reference === null) return;
148
- pendingRef.current = true;
149
- setActionPending(true);
157
+ if (actionKey === null || reference === null || pendingRef.current.has(actionKey)) return;
158
+ pendingRef.current.add(actionKey);
159
+ setPendingKeys(new Set(pendingRef.current));
160
const result = await runAction({
161
environmentId,
162
input: {
@@ -155,8 +165,8 @@ export function usePullRequestActionRunner({
165
...(method ? { mergeMethod: method } : resolveMergeMethod ? { resolveMergeMethod } : {}),
166
},
167
});
158
- pendingRef.current = false;
159
- setActionPending(false);
168
+ pendingRef.current.delete(actionKey);
169
+ setPendingKeys(new Set(pendingRef.current));
170
if (result._tag === "Failure") {
171
toastManager.add({
172
type: "error",