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): the collapsed mobile composer shows Stop while a turn runs (#29959)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
TanJeeSchuan committed
Nov 13, 2026 at 06:57 UTC
e1d59d18840a6f12051e7efefa473f766e80f59c
3 files changed
+212
-78
apps/web/src/components/chat/ChatComposer.tsx
+45
-29
@@ -208,7 +208,7 @@ import {
208
ComposerQueuedAttachmentRow,
209
ComposerRestingImagePreviews,
210
} from "./ComposerAttachmentStrip";
211
-import { ComposerPrimaryActions } from "./ComposerPrimaryActions";
211
+import { CollapsedComposerStopAction, ComposerPrimaryActions } from "./ComposerPrimaryActions";
212
import { ComposerFooterPrimaryActions } from "./ComposerFooterControls";
213
import { ComposerPendingUserInputPanel } from "./ComposerPendingUserInputPanel";
214
import { resolveComposerMenuActiveItemId } from "./composerMenuHighlight";
@@ -3409,35 +3409,51 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
3409
)}
3410
</button>
3411
{collapsedComposerImagePreviews}
3412
- <button
3413
- type="button"
3414
- data-chat-composer-transition-actions="true"
3415
- className="flex size-8 shrink-0 items-center justify-center rounded-full bg-message-action text-message-action-foreground hover:bg-message-action-hover disabled:opacity-64"
3416
- disabled={collapsedComposerPrimaryActionDisabled}
3417
- aria-label={collapsedComposerPrimaryActionLabel}
3418
- onPointerDown={(event) => event.preventDefault()}
3419
- onClick={(event) => {
3420
- event.stopPropagation();
3421
- if (showResumeAction) onResume();
3422
- else if (props.resumeCompactionTokens !== null && !props.keepFullHistory)
3423
- expandMobileComposer();
3424
- else submitComposer();
3425
- }}
3412
+ <CollapsedComposerStopAction
3413
+ key={`${environmentId}:${activeThreadId ?? "new"}`}
3414
+ canOperateThread={canOperateThread}
3415
+ canInterrupt={canInterrupt}
3416
+ runId={activeThread?.runtime?.activeRunId ?? null}
3417
+ hasSendableContent={composerSendState.hasSendableContent}
3418
+ isEditingQueuedMessage={isEditingQueuedMessage}
3419
+ onInterrupt={handleInterruptPrimaryActionStable}
3420
>
3427
- {showResumeAction ? (
3428
- <PlayIcon className="size-4 fill-current" aria-hidden="true" />
3429
- ) : (
3430
- <svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true">
3431
- <path
3432
- d="M8 3L8 13M8 3L4 7M8 3L12 7"
3433
- stroke="currentColor"
3434
- strokeWidth="2"
3435
- strokeLinecap="round"
3436
- strokeLinejoin="round"
3437
- />
3438
- </svg>
3439
- )}
3440
- </button>
3421
+ <button
3422
+ type="button"
3423
+ data-chat-composer-transition-actions="true"
3424
+ className="flex size-8 shrink-0 items-center justify-center rounded-full bg-message-action text-message-action-foreground hover:bg-message-action-hover disabled:opacity-64"
3425
+ disabled={collapsedComposerPrimaryActionDisabled}
3426
+ aria-label={collapsedComposerPrimaryActionLabel}
3427
+ onPointerDown={(event) => event.preventDefault()}
3428
+ onClick={(event) => {
3429
+ event.stopPropagation();
3430
+ if (showResumeAction) onResume();
3431
+ else if (props.resumeCompactionTokens !== null && !props.keepFullHistory)
3432
+ expandMobileComposer();
3433
+ else submitComposer();
3434
+ }}
3435
+ >
3436
+ {showResumeAction ? (
3437
+ <PlayIcon className="size-4 fill-current" aria-hidden="true" />
3438
+ ) : (
3439
+ <svg
3440
+ width="16"
3441
+ height="16"
3442
+ viewBox="0 0 16 16"
3443
+ fill="none"
3444
+ aria-hidden="true"
3445
+ >
3446
+ <path
3447
+ d="M8 3L8 13M8 3L4 7M8 3L12 7"
3448
+ stroke="currentColor"
3449
+ strokeWidth="2"
3450
+ strokeLinecap="round"
3451
+ strokeLinejoin="round"
3452
+ />
3453
+ </svg>
3454
+ )}
3455
+ </button>
3456
+ </CollapsedComposerStopAction>
3457
</div>
3458
) : null}
3459
apps/web/src/components/chat/ComposerPrimaryActions.browser.test.tsx
+31
-1
@@ -13,7 +13,7 @@ vi.mock("../SidebarStageBackdrop", () => ({
13
useSidebarStageBackdropVariant: () => null,
14
}));
15
16
-import { ComposerPrimaryActions } from "./ComposerPrimaryActions";
16
+import { CollapsedComposerStopAction, ComposerPrimaryActions } from "./ComposerPrimaryActions";
17
18
function setup() {
19
return {
@@ -142,3 +142,33 @@ it("keeps a pending stop when the run id clears and resets it for a different ru
142
await screen.rerender(<ComposerPrimaryActions {...props} runId="second" />);
143
expect(screen.getByRole("button", { name: "Stop generation" }).element()).toBeEnabled();
144
});
145
+
146
+it("swaps the collapsed composer's send button for Stop while a turn can be stopped", async () => {
147
+ const onInterrupt = vi.fn();
148
+ const collapsed = (overrides: { canInterrupt?: boolean; hasSendableContent?: boolean } = {}) => (
149
+ <CollapsedComposerStopAction
150
+ canOperateThread
151
+ canInterrupt={overrides.canInterrupt ?? true}
152
+ runId="run"
153
+ hasSendableContent={overrides.hasSendableContent ?? false}
154
+ isEditingQueuedMessage={false}
155
+ onInterrupt={onInterrupt}
156
+ >
157
+ <button type="button">Send message</button>
158
+ </CollapsedComposerStopAction>
159
+ );
160
+ await using screen = await render(collapsed({ hasSendableContent: true }));
161
+ await expect.element(screen.getByRole("button", { name: "Send message" })).toBeVisible();
162
+ await screen.rerender(collapsed());
163
+ await act(() =>
164
+ (
165
+ screen.getByRole("button", { name: "Stop generation" }).element() as HTMLButtonElement
166
+ ).click(),
167
+ );
168
+ expect(onInterrupt).toHaveBeenCalledTimes(1);
169
+ await expect
170
+ .element(screen.getByRole("button", { name: "Stopping", exact: true }))
171
+ .toBeDisabled();
172
+ await screen.rerender(collapsed({ canInterrupt: false }));
173
+ await expect.element(screen.getByRole("button", { name: "Send message" })).toBeVisible();
174
+});
apps/web/src/components/chat/ComposerPrimaryActions.tsx
+136
-48
@@ -94,6 +94,132 @@ const preventPointerFocus: PointerEventHandler<HTMLElement> = (event) => {
94
event.preventDefault();
95
};
96
97
+type StopPhase = "pending" | "timedOut" | "landed" | null;
98
+
99
+function useStopPhase(input: {
100
+ runId: string | null;
101
+ canInterrupt: boolean;
102
+ canOperateThread: boolean;
103
+}) {
104
+ const { runId, canInterrupt, canOperateThread } = input;
105
+ const [stopPhase, setStopPhase] = useState<StopPhase>(null);
106
+ const [stopRunId, setStopRunId] = useState(runId);
107
+ if (runId !== null && stopRunId !== runId) {
108
+ setStopRunId(runId);
109
+ setStopPhase(null);
110
+ } else if (canOperateThread) {
111
+ // Losing permission also clears canInterrupt; it does not acknowledge the stop.
112
+ if ((stopPhase === "pending" || stopPhase === "timedOut") && !canInterrupt)
113
+ setStopPhase("landed");
114
+ else if (stopPhase === "landed" && canInterrupt) setStopPhase(null);
115
+ }
116
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- timer that re-enables Stop if the interrupt never settles
117
+ useEffect(() => {
118
+ if (stopPhase !== "pending") return;
119
+ const timeout = setTimeout(() => setStopPhase("timedOut"), STOP_PENDING_MAX_MS);
120
+ return () => clearTimeout(timeout);
121
+ }, [stopPhase]);
122
+ return [stopPhase, setStopPhase] as const;
123
+}
124
+
125
+function StopGenerationButton({
126
+ stopPhase,
127
+ canOperateThread,
128
+ insidePendingAction,
129
+ preserveComposerFocusOnPointerDown,
130
+ onStopRequested,
131
+ onInterrupt,
132
+}: {
133
+ stopPhase: StopPhase;
134
+ canOperateThread: boolean;
135
+ insidePendingAction: boolean;
136
+ preserveComposerFocusOnPointerDown: boolean;
137
+ onStopRequested: () => void;
138
+ onInterrupt: () => void;
139
+}) {
140
+ const isStopDisabled = stopPhase === "pending" || stopPhase === "landed";
141
+ return (
142
+ <Tooltip>
143
+ <TooltipTrigger
144
+ render={
145
+ <button
146
+ type="button"
147
+ className={cn(
148
+ "flex shrink-0 cursor-pointer items-center justify-center rounded-full bg-destructive/90 text-white shadow-xs shadow-destructive/24 inset-shadow-control-highlight transition-colors duration-150 hover:bg-destructive active:inset-shadow-control-pressed active:shadow-none disabled:cursor-default disabled:opacity-64 disabled:hover:bg-destructive/90 [&_svg]:pointer-events-none",
149
+ insidePendingAction ? "size-8 sm:size-7" : "size-8 sm:h-8 sm:w-8",
150
+ )}
151
+ onPointerDown={preserveComposerFocusOnPointerDown ? preventPointerFocus : undefined}
152
+ disabled={!canOperateThread || isStopDisabled}
153
+ onClick={() => {
154
+ if (!canOperateThread || isStopDisabled) return;
155
+ onStopRequested();
156
+ onInterrupt();
157
+ }}
158
+ aria-label={
159
+ stopPhase === "landed"
160
+ ? "Stopped"
161
+ : stopPhase === "pending"
162
+ ? "Stopping"
163
+ : "Stop generation"
164
+ }
165
+ />
166
+ }
167
+ >
168
+ <svg width="12" height="12" viewBox="0 0 12 12" fill="currentColor" aria-hidden="true">
169
+ <rect x="2" y="2" width="8" height="8" rx="1.5" />
170
+ </svg>
171
+ </TooltipTrigger>
172
+ <TooltipPopup>
173
+ {stopPhase === "pending" ? "Stopping…" : stopPhase === "landed" ? "Stopped" : "Interrupt"}
174
+ </TooltipPopup>
175
+ </Tooltip>
176
+ );
177
+}
178
+
179
+/** The collapsed mobile composer's Stop, shown in place of `children` while a turn can be stopped. */
180
+export function CollapsedComposerStopAction({
181
+ children,
182
+ canOperateThread,
183
+ canInterrupt,
184
+ runId,
185
+ hasSendableContent,
186
+ isEditingQueuedMessage,
187
+ onInterrupt,
188
+}: {
189
+ children: ReactNode;
190
+ canOperateThread: boolean;
191
+ canInterrupt: boolean;
192
+ runId: string | null;
193
+ hasSendableContent: boolean;
194
+ isEditingQueuedMessage: boolean;
195
+ onInterrupt: () => void;
196
+}) {
197
+ const [stopPhase, setStopPhase] = useStopPhase({ runId, canInterrupt, canOperateThread });
198
+ if (
199
+ !(canInterrupt || stopPhase === "pending" || stopPhase === "timedOut") ||
200
+ hasSendableContent ||
201
+ isEditingQueuedMessage
202
+ ) {
203
+ return children;
204
+ }
205
+ return (
206
+ <span
207
+ data-chat-composer-transition-actions="true"
208
+ data-chat-composer-collapsed-controls="true"
209
+ className="flex shrink-0"
210
+ >
211
+ <StopGenerationButton
212
+ stopPhase={stopPhase}
213
+ canOperateThread={canOperateThread}
214
+ insidePendingAction={false}
215
+ preserveComposerFocusOnPointerDown
216
+ onStopRequested={() => setStopPhase("pending")}
217
+ onInterrupt={onInterrupt}
218
+ />
219
+ </span>
220
+ );
221
+}
222
+
223
export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
224
children,
225
compact,
@@ -123,26 +249,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
249
keepFullHistory = false,
250
onToggleKeepFullHistory,
251
}: ComposerPrimaryActionsProps) {
126
- const [stopPhase, setStopPhase] = useState<"pending" | "timedOut" | "landed" | null>(null);
127
- const [stopRunId, setStopRunId] = useState(runId);
128
- if (runId !== null && stopRunId !== runId) {
129
- setStopRunId(runId);
130
- setStopPhase(null);
131
- } else if (canOperateThread) {
132
- // Losing permission also clears canInterrupt; it does not acknowledge the stop.
133
- if ((stopPhase === "pending" || stopPhase === "timedOut") && !canInterrupt)
134
- setStopPhase("landed");
135
- else if (stopPhase === "landed" && canInterrupt) setStopPhase(null);
136
- }
137
- const isStopDisabled = stopPhase === "pending" || stopPhase === "landed";
138
- const stopLabel =
139
- stopPhase === "landed" ? "Stopped" : stopPhase === "pending" ? "Stopping" : "Stop generation";
140
- // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- timer that re-enables Stop if the interrupt never settles
141
- useEffect(() => {
142
- if (stopPhase !== "pending") return;
143
- const timeout = setTimeout(() => setStopPhase("timedOut"), STOP_PENDING_MAX_MS);
144
- return () => clearTimeout(timeout);
145
- }, [stopPhase]);
252
+ const [stopPhase, setStopPhase] = useStopPhase({ runId, canInterrupt, canOperateThread });
253
const pointerFocusProps = preserveComposerFocusOnPointerDown
254
? { onPointerDown: preventPointerFocus }
255
: undefined;
@@ -161,34 +268,15 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
268
const stageBackdropVariant = useSidebarStageBackdropVariant(environmentIdentificationMode);
269
270
const renderStopGenerationButton = (insidePendingAction: boolean) => (
164
- <Tooltip key="interrupt">
165
- <TooltipTrigger
166
- render={
167
- <button
168
- type="button"
169
- className={cn(
170
- "flex shrink-0 cursor-pointer items-center justify-center rounded-full bg-destructive/90 text-white shadow-xs shadow-destructive/24 inset-shadow-control-highlight transition-colors duration-150 hover:bg-destructive active:inset-shadow-control-pressed active:shadow-none disabled:cursor-default disabled:opacity-64 disabled:hover:bg-destructive/90 [&_svg]:pointer-events-none",
171
- insidePendingAction ? "size-8 sm:size-7" : "size-8 sm:h-8 sm:w-8",
172
- )}
173
- {...pointerFocusProps}
174
- disabled={!canOperateThread || isStopDisabled}
175
- onClick={() => {
176
- if (!canOperateThread || isStopDisabled) return;
177
- setStopPhase("pending");
178
- onInterrupt();
179
- }}
180
- aria-label={stopLabel}
181
- />
182
- }
183
- >
184
- <svg width="12" height="12" viewBox="0 0 12 12" fill="currentColor" aria-hidden="true">
185
- <rect x="2" y="2" width="8" height="8" rx="1.5" />
186
- </svg>
187
- </TooltipTrigger>
188
- <TooltipPopup>
189
- {stopPhase === "pending" ? "Stopping…" : stopPhase === "landed" ? "Stopped" : "Interrupt"}
190
- </TooltipPopup>
191
- </Tooltip>
271
+ <StopGenerationButton
272
+ key="interrupt"
273
+ stopPhase={stopPhase}
274
+ canOperateThread={canOperateThread}
275
+ insidePendingAction={insidePendingAction}
276
+ preserveComposerFocusOnPointerDown={preserveComposerFocusOnPointerDown}
277
+ onStopRequested={() => setStopPhase("pending")}
278
+ onInterrupt={onInterrupt}
279
+ />
280
);
281
282
// Keep the clicked target at the right edge even if typing changes the primary action.