@devries-cameron20 / t3code Mirror · read-only / commits / fd6d0ea022
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, 14:45 UTC

fix(web): stashing waits for pasted images to finish compressing (#28308)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Victor committed Nov 14, 2026 at 05:48 UTC fd6d0ea022f1ff6c109f68a8f8db9d199142a0cf
2 files changed +100
apps/web/src/components/chat/useComposerStash.browser.test.tsx new
+89
@@ -0,0 +1,89 @@
1 +import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2 +import { expect, it, vi } from "vite-plus/test";
3 +
4 +import { act, render } from "../../../test/render";
5 +import { DraftId, useComposerDraftStore } from "../../composerDraftStore";
6 +import { removeLocalStorageItem } from "../../hooks/useLocalStorage";
7 +import { isMacPlatform } from "../../lib/utils";
8 +import {
9 + PROMPT_STASH_STORAGE_KEY,
10 + usePromptStashStore,
11 + writePromptStashStorageForTest,
12 +} from "../../promptStashStore";
13 +import {
14 + addPreparingComposerImages,
15 + countPreparingComposerImages,
16 + removePreparingComposerImages,
17 +} from "./preparingComposerImages";
18 +import { useComposerStash } from "./useComposerStash";
19 +
20 +type StashInput = Parameters<typeof useComposerStash>[0];
21 +
22 +function Harness({ input }: { input: StashInput }) {
23 + useComposerStash(input);
24 + return null;
25 +}
26 +
27 +it("keeps the draft when stashing while a pasted image is still compressing", async () => {
28 + const target = DraftId.make("stash-preparing-image");
29 + using _draft = {
30 + [Symbol.dispose]: () => useComposerDraftStore.getState().clearComposerContent(target),
31 + };
32 + using _stash = {
33 + [Symbol.dispose]: () => {
34 + writePromptStashStorageForTest("");
35 + removeLocalStorageItem(PROMPT_STASH_STORAGE_KEY);
36 + },
37 + };
38 + addPreparingComposerImages(target, [
39 + {
40 + id: "pasted",
41 + name: "shot.png",
42 + file: new File(["png"], "shot.png", { type: "image/png" }),
43 + hidden: false,
44 + },
45 + ]);
46 + using _preparing = {
47 + [Symbol.dispose]: () => removePreparingComposerImages(target, new Set(["pasted"])),
48 + };
49 + const environmentId = EnvironmentId.make("stash-env");
50 + const promptRef = { current: "Describe this screenshot" };
51 + const input = {
52 + environmentId,
53 + composerDraftTarget: target,
54 + promptRef,
55 + readAttachmentDraft: () => ({ images: [], files: [] }),
56 + readTerminalContexts: () => [],
57 + routeThreadRef: { environmentId, threadId: ThreadId.make("stash-thread") },
58 + projectSelectionRequired: false,
59 + pendingUserInputs: [],
60 + activePendingProgress: null,
61 + prompt: promptRef.current,
62 + composerMenuOpen: false,
63 + isComposerCollapsedMobile: false,
64 + composerPreviewAnnotations: [],
65 + composerReviewComments: [],
66 + composerThreadContexts: [],
67 + attachmentTargetKey: target,
68 + isComposerDraftTargetOpen: () => true,
69 + composerEditorRef: { current: null },
70 + isRevertingCheckpoint: () => false,
71 + pendingThreadImportsRef: { current: new Map() },
72 + setComposerCursor: vi.fn(),
73 + setComposerTrigger: vi.fn(),
74 + importContextRecords: () => new Map(),
75 + expandMobileComposer: vi.fn(),
76 + } satisfies StashInput;
77 + await using _screen = await render(<Harness input={input} />);
78 +
79 + const mod = isMacPlatform(navigator.platform) ? { metaKey: true } : { ctrlKey: true };
80 + await act(() => {
81 + window.dispatchEvent(
82 + new KeyboardEvent("keydown", { key: "s", ...mod, bubbles: true, cancelable: true }),
83 + );
84 + });
85 +
86 + expect(usePromptStashStore.getState().entries).toEqual([]);
87 + expect(promptRef.current).toBe("Describe this screenshot");
88 + expect(countPreparingComposerImages(target)).toBe(1);
89 +});
apps/web/src/components/chat/useComposerStash.ts
+11
@@ -33,6 +33,7 @@ import { compressImageForStash } from "../../lib/imageCompression";
33 import { formatInlineContextReference } from "~/lib/composerContextReferences";
34 import { isCommandPaletteOpen } from "../../commandPaletteBus";
35 import { pendingDraftWork } from "./pendingDraftWork";
36 +import { countPreparingComposerImages } from "./preparingComposerImages";
37 import {
38 isResponseContextRecord,
39 previewAnnotationContextRecord,
@@ -502,6 +503,16 @@ export function useComposerStash(input: {
503 }
504 return;
505 }
506 + // The snapshot only holds compressed images; a still-compressing one would land in the
507 + // emptied composer instead of travelling with this entry.
508 + if (countPreparingComposerImages(attachmentTargetKey) > 0) {
509 + toastManager.add({
510 + type: "info",
511 + title: "Still compressing a pasted image.",
512 + description: "Stash again once it finishes compressing.",
513 + });
514 + return;
515 + }
516 const stashedFiles: PersistedComposerFileAttachment[] = [];
517 for (const file of files) {
518 if (composerFileNeedsReattach(file)) {