@devries-cameron20 / t3code-1 / commits / 75514dfa55
Fork 0

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

fix(web): keep Ready pending label until its request finishes (#38517)

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

Yash Singh committed Nov 18, 2026 at 03:51 UTC 75514dfa551f155532385cfed1d55408a9bfc5bc
4 files changed +101 -24
apps/web/src/components/chat/ThreadDetailsPrRow.browser.test.tsx
+66 -10
@@ -1,3 +1,4 @@
1 +import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
2 import {
3 EnvironmentId,
4 IssueTrackerKind,
@@ -12,6 +13,7 @@ import { AsyncResult } from "effect/reactivity";
13 import { expect, it, vi } from "vite-plus/test";
14
15 const state = vi.hoisted(() => ({
16 + isDraft: false,
17 status: "success" as PullRequestCheck["status"],
18 extraStatus: null as PullRequestCheck["status"] | null,
19 mergeMethods: ["merge"] as Array<"merge" | "squash" | "rebase">,
@@ -26,6 +28,10 @@ const state = vi.hoisted(() => ({
28 projectMergeMethods: {} as Record<string, "merge" | "squash" | "rebase">,
29 }));
30
31 +vi.mock(import("~/state/use-atom-command"), () => ({
32 + useAtomCommand: (() => state.perform) as never,
33 +}));
34 +
35 vi.mock(import("~/state/entities"), async (importOriginal) => ({
36 ...(await importOriginal()),
37 // Rows render a pull request only with a project, so this does not reach tests that pass none.
@@ -47,7 +53,7 @@ const queryData = () => ({
53 number: 1,
54 title: "Test PR",
55 state: "open",
50 - isDraft: false,
56 + isDraft: state.isDraft,
57 mergeability: "mergeable",
58 headBranch: "feature",
59 baseBranch: "main",
@@ -60,8 +66,8 @@ const queryData = () => ({
66 description: null,
67 url: null,
68 })),
63 - capabilities: { actions: ["merge"], mergeMethods: state.mergeMethods },
64 - viewerPermissions: { actions: ["merge"] },
69 + capabilities: { actions: ["merge", "ready"], mergeMethods: state.mergeMethods },
70 + viewerPermissions: { actions: ["merge", "ready"] },
71 mergeCapabilities: {
72 merge: state.mergeMethods.includes("merge"),
73 squash: state.mergeMethods.includes("squash"),
@@ -87,7 +93,6 @@ vi.mock(import("~/state/query"), async (importOriginal) => ({
93 }));
94 vi.mock(import("../pullRequest/usePullRequestActions"), async (importOriginal) => ({
95 ...(await importOriginal()),
90 - usePullRequestActionRunner: () => ({ actionPending: false, perform: state.perform }),
96 usePullRequestDefaultMergeMethodResolver: ((_environmentId: unknown, projectId: unknown) => () =>
97 state.projectMergeMethods[String(projectId)]) as never,
98 }));
@@ -139,6 +144,9 @@ const repositoryProject = {
144 environmentId: EnvironmentId.make("environment"),
145 title: "repo",
146 workspaceRoot: "/work/repo",
147 + defaultModelSelection: null,
148 + createdAt: "2026-11-18T00:00:00.000Z",
149 + updatedAt: "2026-11-18T00:00:00.000Z",
150 scripts: [],
151 repositoryIdentity: {
152 canonicalKey: "github.com/owner/repo",
@@ -152,7 +160,7 @@ const repositoryProject = {
160 name: "repo",
161 displayName: "owner/repo",
162 },
155 -};
163 +} satisfies EnvironmentProject;
164
165 const clickButton = async (scope: ParentNode, label: string) =>
166 await act(async () => {
@@ -173,7 +181,7 @@ it("merges with the last selected merge method", async () => {
181 pr={null}
182 number={1}
183 status={null}
176 - project={null}
184 + project={repositoryProject}
185 label="Test PR"
186 onOpen={vi.fn()}
187 />,
@@ -189,7 +197,11 @@ it("merges with the last selected merge method", async () => {
197 const dialog = document.querySelector('[role="alertdialog"]')!;
198 expect(dialog.textContent).toContain("using squash");
199 await clickMerge(dialog);
192 - expect(state.perform).toHaveBeenCalledWith("merge", "squash");
200 + expect(state.perform).toHaveBeenCalledWith(
201 + expect.objectContaining({
202 + input: expect.objectContaining({ action: "merge", mergeMethod: "squash" }),
203 + }),
204 + );
205 });
206
207 it("requires a new merge click after passing checks become pending and pass again", async () => {
@@ -201,7 +213,7 @@ it("requires a new merge click after passing checks become pending and pass agai
213 pr={null}
214 number={1}
215 status={null}
204 - project={null}
216 + project={repositoryProject}
217 label="Test PR"
218 onOpen={vi.fn()}
219 />
@@ -233,7 +245,7 @@ it("requires a new merge click after passing checks become pending and pass agai
245 });
246
247 async function setup() {
236 - state.perform.mockReset();
248 + state.perform.mockReset().mockResolvedValue({ _tag: "Success", value: undefined });
249 state.checkoutError = null;
250 state.newThread.mockReset().mockResolvedValue({
251 draftId: DraftId.make("new-draft"),
@@ -243,6 +255,7 @@ async function setup() {
255 state.addToast.mockReset().mockReturnValue("checkout-toast");
256 state.updateToast.mockReset();
257
258 + state.isDraft = false;
259 state.status = "success";
260 state.extraStatus = null;
261 state.mergeMethods = ["merge"];
@@ -264,7 +277,7 @@ it("adds the failing checks to a given composer instead of opening a new thread"
277 pr={null}
278 number={1}
279 status={null}
267 - project={null}
280 + project={repositoryProject}
281 label="Test PR"
282 onOpen={vi.fn()}
283 composerTarget={threadRef}
@@ -402,3 +415,46 @@ it("names a linked issue row by its kind, number and title, not its URL", async
415 expect(name).toContain("#123");
416 expect(name).toContain("Sidebar flickers on resize");
417 });
418 +
419 +it("keeps Ready pending when refreshed detail becomes mergeable before the action settles", async () => {
420 + await using screen = await setup();
421 + const row = () => (
422 + <ThreadDetailsPrRow
423 + environmentId={EnvironmentId.make("environment")}
424 + pr={null}
425 + number={1}
426 + status={null}
427 + project={repositoryProject}
428 + label="Test PR"
429 + onOpen={vi.fn()}
430 + />
431 + );
432 + let finish!: (result: { _tag: "Success"; value: undefined }) => void;
433 + const result = new Promise<{ _tag: "Success"; value: undefined }>((resolve) => {
434 + finish = resolve;
435 + });
436 + state.perform.mockReturnValueOnce(result);
437 + state.isDraft = true;
438 + await screen.rerender(row());
439 + await clickButton(screen.container, "Ready");
440 + expect(state.perform).toHaveBeenCalledWith(
441 + expect.objectContaining({
442 + input: expect.objectContaining({
443 + projectId: repositoryProject.id,
444 + repository: "owner/repo",
445 + number: 1,
446 + action: "ready",
447 + }),
448 + }),
449 + );
450 + await expect.element(screen.getByRole("button", { name: "Marking..." })).toBeDisabled();
451 +
452 + state.isDraft = false;
453 + await screen.rerender(row());
454 + await expect.element(screen.getByRole("button", { name: "Marking..." })).toBeDisabled();
455 + await act(async () => {
456 + finish({ _tag: "Success", value: undefined });
457 + await result;
458 + });
459 + await expect.element(screen.getByRole("button", { name: "Merge", exact: true })).toBeEnabled();
460 +});
apps/web/src/components/chat/ThreadDetailsPrRow.tsx
+5 -2
@@ -166,7 +166,7 @@ export function ThreadDetailsPrRow({
166 checks: detail?.checks ?? [],
167 });
168
169 - const { actionPending, perform } = usePullRequestActionRunner({
169 + const { actionPending, pendingAction, perform } = usePullRequestActionRunner({
170 environmentId,
171 reference,
172 terminology,
@@ -183,7 +183,10 @@ export function ThreadDetailsPrRow({
183 );
184 const [confirmingMerge, setConfirmingMerge] = useState(false);
185
186 - const rowAction = resolveThreadPanelPullRequestAction(detail);
186 + const rowAction =
187 + pendingAction === "ready" || pendingAction === "merge"
188 + ? pendingAction
189 + : resolveThreadPanelPullRequestAction(detail);
190 if (confirmingMerge && rowAction !== "merge") {
191 setConfirmingMerge(false);
192 }
apps/web/src/components/pullRequest/usePullRequestActions.browser.test.tsx
+19 -5
@@ -32,19 +32,26 @@ function deferred<T>() {
32 }
33
34 function MergeButton({ reference }: { reference: PullRequestRef }) {
35 - const { actionPending, perform } = usePullRequestActionRunner({
35 + const { actionPending, pendingAction, perform } = usePullRequestActionRunner({
36 environmentId: EnvironmentId.make("environment"),
37 reference,
38 terminology: sourceControlClients.get(undefined).changeRequest,
39 });
40 return (
41 <button type="button" disabled={actionPending} onClick={() => void perform("merge")}>
42 - {actionPending ? "Merging..." : "Merge"}
42 + {pendingAction === "merge" ? "Merging..." : "Merge"}
43 </button>
44 );
45 }
46
47 +function setup() {
48 + state.runAction.mockReset();
49 + state.newThread.mockReset();
50 + state.prepareThread.mockReset();
51 +}
52 +
53 it("keeps pending merges with their pull request when navigating between threads", async () => {
54 + setup();
55 const first: PullRequestRef = {
56 projectId: ProjectId.make("project"),
57 repository: "owner/repo",
@@ -54,7 +61,6 @@ it("keeps pending merges with their pull request when navigating between threads
61 const firstResult = deferred<{ _tag: "Success"; value: void }>();
62 const secondResult = deferred<{ _tag: "Success"; value: void }>();
63 state.runAction
57 - .mockReset()
64 .mockReturnValueOnce(firstResult.promise)
65 .mockReturnValueOnce(secondResult.promise);
66 await using screen = await render(<MergeButton reference={first} />);
@@ -62,6 +68,14 @@ it("keeps pending merges with their pull request when navigating between threads
68
69 await userEvent.click(button);
70 await expect.element(button).toHaveTextContent("Merging...");
71 + await screen.rerender(
72 + <MergeButton reference={{ ...first, projectId: ProjectId.make("other-project") }} />,
73 + );
74 + await expect.element(button).toHaveTextContent("Merge");
75 + await expect.element(button).toBeEnabled();
76 + await screen.rerender(<MergeButton reference={first} />);
77 + await expect.element(button).toHaveTextContent("Merging...");
78 + await expect.element(button).toBeDisabled();
79 await screen.rerender(<MergeButton reference={second} />);
80 await expect.element(button).toHaveTextContent("Merge");
81 await expect.element(button).toBeEnabled();
@@ -102,6 +116,7 @@ function FixChecksButton() {
116 }
117
118 it("stops a pull request handoff when its loading toast is dismissed", async () => {
119 + setup();
120 const prepared = deferred<{
121 _tag: "Success";
122 value: {
@@ -112,10 +127,9 @@ it("stops a pull request handoff when its loading toast is dismissed", async ()
127 };
128 }>();
129 state.newThread
115 - .mockReset()
130 .mockResolvedValueOnce({ draftId: "draft-1", threadId: ThreadId.make("thread-1") })
131 .mockResolvedValueOnce({ draftId: "draft-2", threadId: ThreadId.make("thread-1") });
118 - state.prepareThread.mockReset().mockReturnValueOnce(prepared.promise);
132 + state.prepareThread.mockReturnValueOnce(prepared.promise);
133 await using screen = await render(
134 <ToastProvider>
135 <FixChecksButton />
apps/web/src/components/pullRequest/usePullRequestActions.ts
+11 -7
@@ -201,23 +201,27 @@ export function usePullRequestActionRunner({
201 const runAction = useAtomCommand(pullRequestEnvironment.runAction, {
202 reportFailure: false,
203 });
204 - const pendingRef = useRef(new Set<string>());
205 - const [pendingKeys, setPendingKeys] = useState<ReadonlySet<string>>(() => new Set());
204 + const pendingRef = useRef(new Map<string, PullRequestAction>());
205 + const [pendingActions, setPendingActions] = useState<ReadonlyMap<string, PullRequestAction>>(
206 + () => new Map(),
207 + );
208 const actionKey =
209 reference === null
210 ? null
211 : JSON.stringify([
212 environmentId,
213 + reference.projectId,
214 reference.host ?? null,
215 reference.repository,
216 reference.number,
217 ]);
215 - const actionPending = actionKey !== null && pendingKeys.has(actionKey);
218 + const pendingAction = actionKey === null ? null : (pendingActions.get(actionKey) ?? null);
219 + const actionPending = pendingAction !== null;
220
221 const perform = async (action: PullRequestAction, method?: PullRequestMergeMethod) => {
222 if (actionKey === null || reference === null || pendingRef.current.has(actionKey)) return;
219 - pendingRef.current.add(actionKey);
220 - setPendingKeys(new Set(pendingRef.current));
223 + pendingRef.current.set(actionKey, action);
224 + setPendingActions(new Map(pendingRef.current));
225 const result = await runAction({
226 environmentId,
227 input: {
@@ -227,7 +231,7 @@ export function usePullRequestActionRunner({
231 },
232 });
233 pendingRef.current.delete(actionKey);
230 - setPendingKeys(new Set(pendingRef.current));
234 + setPendingActions(new Map(pendingRef.current));
235 if (result._tag === "Failure") {
236 toastManager.add({
237 type: "error",
@@ -246,7 +250,7 @@ export function usePullRequestActionRunner({
250 onSuccess?.(action, result.value);
251 };
252
249 - return { actionPending, perform };
253 + return { actionPending, pendingAction, perform };
254 }
255
256 export function usePullRequestCloseBatch(