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, 11:00 UTC
fix(web): an image-only send that fails behind a new draft now says so (#32732)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Victor committed
Nov 15, 2026 at 00:39 UTC
ca31ab64a45596b67185e947ead6286bc234c9c3
3 files changed
+135
-21
apps/web/src/components/ChatView.browser.test.tsx
+95
-1
@@ -1,12 +1,19 @@
1
import { createMemoryHistory } from "@tanstack/react-router";
2
import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment";
3
-import { EnvironmentId, RunId, ThreadId } from "@t3tools/contracts";
3
+import {
4
+ EnvironmentId,
5
+ ORCHESTRATION_V2_WS_METHODS,
6
+ RunId,
7
+ ThreadId,
8
+ WS_METHODS,
9
+} from "@t3tools/contracts";
10
import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
11
import {
12
compileResolvedKeybindingsConfig,
13
mergeWithDefaultKeybindings,
14
} from "@t3tools/shared/keybindings";
15
import type * as Context from "effect/Context";
16
+import * as Effect from "effect/Effect";
17
import { expect, it, vi } from "vite-plus/test";
18
import { cdp, page, userEvent } from "vite-plus/test/browser";
19
@@ -28,6 +35,7 @@ import {
35
ENVIRONMENT_ID,
36
PROJECT_ID,
37
answerAssetUrls,
38
+ answerRpc,
39
assistantItem,
40
dispatchedCommands,
41
emitThreadEvent,
@@ -40,6 +48,47 @@ import {
48
} from "../../test/fakeEnvironment";
49
import { act, fakeTimers, render } from "../../test/render";
50
51
+const PNG = Uint8Array.from(
52
+ atob(
53
+ "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",
54
+ ),
55
+ (char) => char.charCodeAt(0),
56
+);
57
+
58
+/** Accepts every attachment upload without sending its bytes, until disposed. */
59
+function acceptAttachmentUploads(): Disposable {
60
+ const mint = answerRpc(WS_METHODS.attachmentsCreateUploadUrl, () =>
61
+ Effect.succeed({ attachmentId: "upload-1", relativeUrl: "/upload", expiresAt: 0 }),
62
+ );
63
+ const status = vi.spyOn(XMLHttpRequest.prototype, "status", "get").mockReturnValue(200);
64
+ const send = vi.spyOn(XMLHttpRequest.prototype, "send").mockImplementation(function (
65
+ this: XMLHttpRequest,
66
+ ) {
67
+ queueMicrotask(() => this.dispatchEvent(new ProgressEvent("load")));
68
+ });
69
+ return {
70
+ [Symbol.dispose]: () => {
71
+ send.mockRestore();
72
+ status.mockRestore();
73
+ mint[Symbol.dispose]();
74
+ },
75
+ };
76
+}
77
+
78
+/** Holds every call to `method` until `release`, then ends it with `end`, until disposed. */
79
+function holdRpc<Input>(method: string, end: Effect.Effect<never, Error>) {
80
+ let release = () => {};
81
+ const held = new Promise<void>((resolve) => {
82
+ release = resolve;
83
+ });
84
+ const calls: Input[] = [];
85
+ const answer = answerRpc(method, (input: Input) => {
86
+ calls.push(input);
87
+ return Effect.promise(() => held).pipe(Effect.andThen(end));
88
+ });
89
+ return { calls, release, [Symbol.dispose]: () => answer[Symbol.dispose]() };
90
+}
91
+
92
// The socket is the only fake layer; see test/appScenarios.renders.tsx.
93
vi.mock("../../../../packages/client-runtime/src/connection/driver.ts", async (importOriginal) => {
94
const [actual, { fakeDriver }, Layer] = await Promise.all([
@@ -197,6 +246,51 @@ it("a new draft does not load its reserved thread before the server lists it", a
246
expect(threadRequests).toEqual([]);
247
});
248
249
+it("an interrupted image-only first send of a new thread says it may not have been sent", async () => {
250
+ using _environment = installFakeEnvironment([]);
251
+ __setClientSettingsForTests({
252
+ ...DEFAULT_CLIENT_SETTINGS,
253
+ onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
254
+ });
255
+ const draftId = DraftId.make("draft-image-only-interrupted");
256
+ useComposerDraftStore
257
+ .getState()
258
+ .setProjectDraftThreadId(scopeProjectRef(ENVIRONMENT_ID, PROJECT_ID), draftId, {
259
+ threadId: ThreadId.make("thread-image-only-interrupted"),
260
+ });
261
+ // A dropped connection interrupts a new thread's launch, which is not resent.
262
+ using launch = holdRpc(ORCHESTRATION_V2_WS_METHODS.launchThread, Effect.interrupt);
263
+ const router = getRouter(createMemoryHistory({ initialEntries: [`/draft/${draftId}`] }));
264
+ await router.load();
265
+ await using _app = await render(<AppRoot router={router} />, {
266
+ // AppRoot brings its own router.
267
+ router: false,
268
+ });
269
+ using _uploads = acceptAttachmentUploads();
270
+ const editor = page.getByTestId("composer-editor");
271
+ await expect.element(editor).toBeVisible();
272
+ // The send needs the project, which arrives with the shell snapshot.
273
+ await expect.element(page.getByText("render", { exact: true }).first()).toBeVisible();
274
+
275
+ await userEvent.click(editor);
276
+ const clipboardData = new DataTransfer();
277
+ clipboardData.items.add(new File([PNG], "shot.png", { type: "image/png" }));
278
+ editor
279
+ .element()
280
+ .dispatchEvent(new ClipboardEvent("paste", { clipboardData, bubbles: true, cancelable: true }));
281
+ await expect.element(page.getByRole("img", { name: "shot.png" })).toBeVisible();
282
+ await userEvent.keyboard("{Enter}");
283
+ await vi.waitFor(() => expect(launch.calls).toHaveLength(1));
284
+ await userEvent.keyboard("next draft");
285
+ await expect.element(editor).toHaveTextContent("next draft");
286
+ launch.release();
287
+
288
+ await expect.element(page.getByText("Message may not have been sent")).toBeVisible();
289
+ await expect.element(editor).toHaveTextContent("next draft");
290
+ // With no text there is nothing to copy.
291
+ expect(page.getByText("Copy message", { exact: true }).query()).toBeNull();
292
+});
293
+
294
it("opens the thread actions menu for an older settled thread the shell leaves out", async () => {
295
const thread = { ...threadWithHistory("older-settled", 1), olderSettled: true as const };
296
using _environment = installFakeEnvironment([thread]);
apps/web/src/components/chat/useComposerSend.ts
+28
-20
@@ -1410,26 +1410,34 @@ export function useComposerSend(input: ComposerSendInput) {
1410
) {
1411
// A draft typed meanwhile keeps the composer, so the failed text stays reachable here.
1412
const failedText = sendSnapshot.draftText;
1413
- if (failedText.trim().length > 0) {
1414
- toastManager.add(
1415
- stackedThreadToast({
1416
- type: "error",
1417
- title: isAtomCommandInterrupted(failure)
1418
- ? "Message may not have been sent"
1419
- : "Message not sent",
1420
- description: "Your new draft was kept. Copy the failed message to send it again.",
1421
- // The toast holds the only copy of the failed text, so it stays until dismissed.
1422
- timeout: 0,
1423
- data: { hideCopyButton: true },
1424
- actionProps: {
1425
- children: "Copy message",
1426
- onClick: () => {
1427
- void writeTextToClipboard(failedText, "failed message").catch(() => undefined);
1428
- },
1429
- },
1430
- }),
1431
- );
1432
- }
1413
+ const hasText = failedText.trim().length > 0;
1414
+ // An image-only message has nothing to copy, but its failure still needs a notice.
1415
+ toastManager.add(
1416
+ stackedThreadToast({
1417
+ type: "error",
1418
+ title: isAtomCommandInterrupted(failure)
1419
+ ? "Message may not have been sent"
1420
+ : "Message not sent",
1421
+ description: hasText
1422
+ ? "Your new draft was kept. Copy the failed message to send it again."
1423
+ : "Your new draft was kept.",
1424
+ // The toast holds the only trace of the failed message, so it stays until dismissed.
1425
+ timeout: 0,
1426
+ data: { hideCopyButton: true },
1427
+ ...(hasText
1428
+ ? {
1429
+ actionProps: {
1430
+ children: "Copy message",
1431
+ onClick: () => {
1432
+ void writeTextToClipboard(failedText, "failed message").catch(
1433
+ () => undefined,
1434
+ );
1435
+ },
1436
+ },
1437
+ }
1438
+ : {}),
1439
+ }),
1440
+ );
1441
} else {
1442
const retryComposerImages = restoreComposerDraft(composerDraftTarget, sendSnapshot);
1443
if (currentRouteThreadKeyRef.current === routeThreadKey) {
apps/web/test/fakeEnvironment.ts
+12
@@ -656,6 +656,18 @@ export function dispatchedCommands(): ReadonlyArray<OrchestrationV2Command> {
656
657
type ThreadEvent = Extract<OrchestrationV2ThreadStreamItem, { readonly kind: "event" }>["event"];
658
659
+/** Answers one RPC method with `handler` until disposed. */
660
+export function answerRpc(method: string, handler: (input: never) => unknown): Disposable {
661
+ const previous = handlers[method];
662
+ handlers[method] = handler;
663
+ return {
664
+ [Symbol.dispose]: () => {
665
+ if (previous) handlers[method] = previous;
666
+ else delete handlers[method];
667
+ },
668
+ };
669
+}
670
+
671
export async function emitTerminalMetadata(event: TerminalMetadataStreamEvent): Promise<void> {
672
if (terminalMetadataSubscriber === null) throw new Error("No terminal metadata subscription");
673
await Effect.runPromise(Queue.offer(terminalMetadataSubscriber, event));