@devries-cameron20 / t3code-1 / commits / 9411a71ec0
Fork 0

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

fix(web): dismissing the pull request checkout toast stops the handoff (#34509)

Julius Marminge committed Nov 11, 2026 at 16:04 UTC 9411a71ec0fab7fdedb4799b78402ec8a46e0d0e
2 files changed +95 -3
apps/web/src/components/pullRequest/usePullRequestActions.browser.test.tsx
+76 -3
@@ -1,15 +1,27 @@
1 -import { EnvironmentId, ProjectId, type PullRequestRef } from "@t3tools/contracts";
1 +import { EnvironmentId, ProjectId, ThreadId, 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";
7 +import { useComposerDraftStore } from "~/composerDraftStore";
8 +import { ToastProvider } from "../ui/toast";
9 +import { usePullRequestActionRunner, usePullRequestHandoffs } from "./usePullRequestActions";
10
9 -const state = vi.hoisted(() => ({ runAction: vi.fn() }));
11 +const state = vi.hoisted(() => ({
12 + runAction: vi.fn(),
13 + newThread: vi.fn(),
14 + prepareThread: vi.fn(),
15 +}));
16 vi.mock(import("~/state/use-atom-command"), () => ({
17 useAtomCommand: (() => state.runAction) as never,
18 }));
19 +vi.mock(import("~/hooks/useHandleNewThread"), () => ({
20 + useNewThreadHandler: (() => state.newThread) as never,
21 +}));
22 +vi.mock(import("~/state/sourceControlActions"), () => ({
23 + usePreparePullRequestThreadAction: (() => ({ run: state.prepareThread })) as never,
24 +}));
25
26 function deferred<T>() {
27 let resolve!: (value: T) => void;
@@ -72,3 +84,64 @@ it("keeps pending merges with their pull request when navigating between threads
84 });
85 await expect.element(button).toHaveTextContent("Merge");
86 });
87 +
88 +function FixChecksButton() {
89 + const { startHandoff } = usePullRequestHandoffs({
90 + environmentId: EnvironmentId.make("environment"),
91 + detail: {
92 + projectId: ProjectId.make("project"),
93 + workspaceRoot: "/repo",
94 + url: "https://github.com/owner/repo/pull/1",
95 + },
96 + });
97 + return (
98 + <button type="button" onClick={() => void startHandoff("fix", { prompt: "Fix the checks" })}>
99 + Fix
100 + </button>
101 + );
102 +}
103 +
104 +it("stops a pull request handoff when its loading toast is dismissed", async () => {
105 + const prepared = deferred<{
106 + _tag: "Success";
107 + value: {
108 + branch: string;
109 + worktreePath: string;
110 + isOnPullRequestHead: boolean;
111 + pullRequest: { url: string };
112 + };
113 + }>();
114 + state.newThread
115 + .mockReset()
116 + .mockResolvedValueOnce({ draftId: "draft-1", threadId: ThreadId.make("thread-1") })
117 + .mockResolvedValueOnce({ draftId: "draft-2", threadId: ThreadId.make("thread-1") });
118 + state.prepareThread.mockReset().mockReturnValueOnce(prepared.promise);
119 + await using screen = await render(
120 + <ToastProvider>
121 + <FixChecksButton />
122 + </ToastProvider>,
123 + );
124 +
125 + await userEvent.click(screen.getByRole("button", { name: "Fix" }));
126 + const toast = screen.getByRole("dialog", { name: "Preparing the pull request checkout..." });
127 + await expect.element(toast).toBeVisible();
128 + await userEvent.click(toast.getByRole("button", { name: "Dismiss notification" }));
129 + await expect.element(toast).not.toBeInTheDocument();
130 + await act(async () => {
131 + prepared.resolve({
132 + _tag: "Success",
133 + value: {
134 + branch: "pr-1",
135 + worktreePath: "/repo-worktrees/pr-1",
136 + isOnPullRequestHead: true,
137 + pullRequest: { url: "https://github.com/owner/repo/pull/1" },
138 + },
139 + });
140 + await prepared.promise;
141 + });
142 +
143 + expect(state.newThread).toHaveBeenCalledTimes(1);
144 + expect(useComposerDraftStore.getState().getComposerDraft("draft-2" as never)?.prompt ?? "").toBe(
145 + "",
146 + );
147 +});
apps/web/src/components/pullRequest/usePullRequestActions.ts
+19
@@ -332,10 +332,17 @@ export function usePullRequestHandoffs({
332 ) => {
333 if (!detail || handoff !== null) return;
334 setHandoff(kind);
335 + // Dismissing the loading toast cancels the handoff before it touches a draft.
336 + let cancelled = false;
337 // Explicit timeouts survive toast updates and would pin the result after loading.
338 const toastId = toastManager.add({
339 type: "loading",
340 title: `Preparing the ${terminology.singular} checkout...`,
341 + data: {
342 + onClose: () => {
343 + cancelled = true;
344 + },
345 + },
346 });
347 const projectRef = scopeProjectRef(environmentId, detail.projectId);
348 // Checkout setup requires the thread to exist first.
@@ -343,6 +350,10 @@ export function usePullRequestHandoffs({
350 (session) => session,
351 () => null,
352 );
353 + if (cancelled) {
354 + setHandoff(null);
355 + return;
356 + }
357 if (opened === null) {
358 setHandoff(null);
359 toastManager.update(toastId, {
@@ -357,6 +368,10 @@ export function usePullRequestHandoffs({
368 mode,
369 threadId: opened.threadId,
370 });
371 + if (cancelled) {
372 + setHandoff(null);
373 + return;
374 + }
375 if (prepared._tag === "Failure") {
376 setHandoff(null);
377 toastManager.update(toastId, {
@@ -376,6 +391,10 @@ export function usePullRequestHandoffs({
391 (session) => session,
392 () => null,
393 );
394 + if (cancelled) {
395 + setHandoff(null);
396 + return;
397 + }
398 if (pointed === null) {
399 setHandoff(null);
400 toastManager.update(toastId, {