@devries-cameron20 / t3code Mirror · read-only / commits / 442b1db161
Fork 0

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 21, 18:30 UTC

fix(web): Resume replaces Stop without a lingering Stopped button (#35755)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 12, 2026 at 18:09 UTC 442b1db1612e222f569569b4dbd15769785db691
2 files changed +81 -46
apps/web/src/components/chat/ComposerPrimaryActions.browser.test.tsx
+50 -28
@@ -35,13 +35,34 @@ function setup() {
35 } satisfies ComponentProps<typeof ComposerPrimaryActions>;
36 }
37
38 -it.each([false, true])(
39 - "keeps repeat clicks away from Resume and Send (draft: %s)",
40 - async (draft) => {
38 +it.each(["resume", "draft", "question"] as const)(
39 + "keeps repeat Stop clicks from reaching the action that replaces it (%s)",
40 + async (mode) => {
41 const props = setup();
42 - const container = document.createElement("div");
43 - Object.assign(container.style, { display: "flex", justifyContent: "flex-end", width: "400px" });
44 - await using screen = await render(<ComposerPrimaryActions {...props} />, { container });
42 + const submit = vi.fn();
43 + const pendingAction =
44 + mode === "question"
45 + ? {
46 + questionIndex: 0,
47 + isLastQuestion: true,
48 + canAdvance: true,
49 + isResponding: false,
50 + isComplete: true,
51 + }
52 + : null;
53 + const view = (overrides: Partial<ComponentProps<typeof ComposerPrimaryActions>> = {}) => (
54 + <form
55 + style={{ display: "flex", justifyContent: "flex-end", width: "400px" }}
56 + onSubmit={(event) => {
57 + event.preventDefault();
58 + submit();
59 + }}
60 + >
61 + <ComposerPrimaryActions {...props} pendingAction={pendingAction} {...overrides} />
62 + </form>
63 + );
64 + await using screen = await render(view());
65 + using _timers = fakeTimers();
66 const stop = screen
67 .getByRole("button", { name: "Stop generation" })
68 .element() as HTMLButtonElement;
@@ -54,35 +75,34 @@ it.each([false, true])(
75 screen.getByRole("button", { name: "Stopping", exact: true }).element() as HTMLButtonElement
76 ).click(),
77 );
57 - await expect
58 - .element(screen.getByRole("button", { name: "Stopping", exact: true }))
59 - .toBeDisabled();
78 + expect(screen.getByRole("button", { name: "Stopping", exact: true }).element()).toBeDisabled();
79 expect(props.onInterrupt).toHaveBeenCalledTimes(1);
80 await screen.rerender(
62 - <ComposerPrimaryActions
63 - {...props}
64 - isRunning={false}
65 - canInterrupt={false}
66 - canResume
67 - hasSendableContent={draft}
68 - />,
81 + view({
82 + isRunning: false,
83 + canInterrupt: false,
84 + canResume: true,
85 + hasSendableContent: mode === "draft",
86 + }),
87 );
70 - await expect
71 - .element(screen.getByRole("button", { name: "Stopped", exact: true }))
72 - .toBeDisabled();
73 - expect(target()).toHaveAttribute("aria-label", "Stopped");
88 + const action = { resume: "Resume thread", draft: "Submit message", question: "Submit" }[mode];
89 + expect(screen.getByRole("button", { name: "Stop generation" }).query()).toBeNull();
90 + expect(target()).toBe(screen.getByRole("button", { name: action, exact: true }).element());
91 await act(() => {
92 for (let i = 0; i < 20; i++) target()?.click();
93 });
94 + await act(() => vi.advanceTimersByTime(499));
95 + await act(() => target()?.click());
96 expect(props.onResume).not.toHaveBeenCalled();
97 expect(props.onSubmitMessage).not.toHaveBeenCalled();
79 - const action = screen
80 - .getByRole("button", { name: draft ? "Submit message" : "Resume thread" })
81 - .element() as HTMLButtonElement;
82 - await act(() => action.click());
83 - expect(draft ? props.onSubmitMessage : props.onResume).toHaveBeenCalledTimes(1);
84 - await screen.rerender(<ComposerPrimaryActions {...props} />);
85 - await expect.element(screen.getByRole("button", { name: "Stop generation" })).toBeEnabled();
98 + expect(submit).not.toHaveBeenCalled();
99 + await act(() => vi.advanceTimersByTime(1));
100 + await act(() => target()?.click());
101 + expect(
102 + { resume: props.onResume, draft: props.onSubmitMessage, question: submit }[mode],
103 + ).toHaveBeenCalledTimes(1);
104 + await screen.rerender(view());
105 + expect(screen.getByRole("button", { name: "Stop generation" }).element()).toBeEnabled();
106 },
107 );
108
@@ -106,7 +126,9 @@ it("allows retry after ten seconds and protects a late stop", async () => {
126 await screen.rerender(
127 <ComposerPrimaryActions {...props} isRunning={false} canInterrupt={false} canResume />,
128 );
109 - expect(screen.getByRole("button", { name: "Stopped", exact: true }).element()).toBeDisabled();
129 + await act(() =>
130 + (screen.getByRole("button", { name: "Resume thread" }).element() as HTMLButtonElement).click(),
131 + );
132 expect(props.onInterrupt).toHaveBeenCalledTimes(2);
133 expect(props.onResume).not.toHaveBeenCalled();
134 });
apps/web/src/components/chat/ComposerPrimaryActions.tsx
+31 -18
@@ -86,6 +86,8 @@ const formatPendingPrimaryActionLabel = (input: {
86 };
87
88 const STOP_PENDING_MAX_MS = 10_000;
89 +// The action that takes Stop's place ignores clicks this long, so repeat Stop clicks can't resume.
90 +const STOP_LANDED_CLICK_GUARD_MS = 500;
91
92 const messageActionPillClassName =
93 "inline-flex shrink-0 cursor-pointer items-center justify-center gap-1.5 whitespace-nowrap rounded-full bg-message-action font-medium text-base text-message-action-foreground shadow-xs shadow-message-action/24 outline-none hover:bg-message-action-hover focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-64 disabled:shadow-none sm:text-sm";
@@ -113,11 +115,16 @@ function useStopPhase(input: {
115 setStopPhase("landed");
116 else if (stopPhase === "landed" && canInterrupt) setStopPhase(null);
117 }
116 - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- timer that re-enables Stop if the interrupt never settles
118 + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- timers that re-enable an unsettled Stop and end the landed click guard
119 useEffect(() => {
118 - if (stopPhase !== "pending") return;
119 - const timeout = setTimeout(() => setStopPhase("timedOut"), STOP_PENDING_MAX_MS);
120 - return () => clearTimeout(timeout);
120 + if (stopPhase === "pending") {
121 + const timeout = setTimeout(() => setStopPhase("timedOut"), STOP_PENDING_MAX_MS);
122 + return () => clearTimeout(timeout);
123 + }
124 + if (stopPhase === "landed") {
125 + const timeout = setTimeout(() => setStopPhase(null), STOP_LANDED_CLICK_GUARD_MS);
126 + return () => clearTimeout(timeout);
127 + }
128 }, [stopPhase]);
129 return [stopPhase, setStopPhase] as const;
130 }
@@ -137,7 +144,7 @@ function StopGenerationButton({
144 onStopRequested: () => void;
145 onInterrupt: () => void;
146 }) {
140 - const isStopDisabled = stopPhase === "pending" || stopPhase === "landed";
147 + const isStopDisabled = stopPhase === "pending";
148 return (
149 <Tooltip>
150 <TooltipTrigger
@@ -155,13 +162,7 @@ function StopGenerationButton({
162 onStopRequested();
163 onInterrupt();
164 }}
158 - aria-label={
159 - stopPhase === "landed"
160 - ? "Stopped"
161 - : stopPhase === "pending"
162 - ? "Stopping"
163 - : "Stop generation"
164 - }
165 + aria-label={stopPhase === "pending" ? "Stopping" : "Stop generation"}
166 />
167 }
168 >
@@ -169,9 +170,7 @@ function StopGenerationButton({
170 <rect x="2" y="2" width="8" height="8" rx="1.5" />
171 </svg>
172 </TooltipTrigger>
172 - <TooltipPopup>
173 - {stopPhase === "pending" ? "Stopping…" : stopPhase === "landed" ? "Stopped" : "Interrupt"}
174 - </TooltipPopup>
173 + <TooltipPopup>{stopPhase === "pending" ? "Stopping…" : "Interrupt"}</TooltipPopup>
174 </Tooltip>
175 );
176 }
@@ -283,7 +282,9 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
282 const withStopButton = (action: ReactNode) => (
283 <>
284 {action}
286 - {stopPhase === null ? null : renderStopGenerationButton(false)}
285 + {stopPhase === "pending" || stopPhase === "timedOut"
286 + ? renderStopGenerationButton(false)
287 + : null}
288 </>
289 );
290
@@ -319,6 +320,9 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
320 type="submit"
321 className={cn(messageActionPillClassName, "h-8 sm:h-7", compact ? "px-3" : "px-4")}
322 {...pointerFocusProps}
323 + onClick={(event) => {
324 + if (stopPhase === "landed") event.preventDefault();
325 + }}
326 disabled={
327 !canOperateThread ||
328 isEnvironmentUnavailable ||
@@ -337,7 +341,9 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
341 questionIndex: pendingAction.questionIndex,
342 })}
343 </button>
340 - {canInterrupt || stopPhase !== null ? renderStopGenerationButton(true) : null}
344 + {canInterrupt || stopPhase === "pending" || stopPhase === "timedOut"
345 + ? renderStopGenerationButton(true)
346 + : null}
347 </div>
348 );
349 }
@@ -402,7 +408,14 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
408 : "bg-message-action text-message-action-foreground enabled:shadow-message-action/24 hover:bg-message-action-hover disabled:bg-foreground/12 disabled:text-muted-foreground",
409 )}
410 {...pointerFocusProps}
405 - onClick={showResume ? onResume : onSubmitMessage}
411 + onClick={(event) => {
412 + if (stopPhase === "landed") {
413 + event.preventDefault();
414 + return;
415 + }
416 + if (showResume) onResume?.();
417 + else onSubmitMessage?.(event);
418 + }}
419 disabled={
420 isSendBusy ||
421 isSendDisabled ||