The best way to control Claude Code, Codex and more from any computer or phone
fix(web): draft images keep their order after a reload (#32709)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Victor committed
Nov 15, 2026 at 00:25 UTC
8e06750a08ae7a0c42054d4fc8bfbf6df7056051
2 files changed
+21
-9
apps/web/src/components/chat/composerImagePersistence.test.ts
+16
@@ -77,6 +77,22 @@ describe("serializeComposerImages", () => {
77
expect(readFileAsDataUrl).not.toHaveBeenCalled();
78
});
79
80
+ it("keeps composer order when a later image finishes reading first", async () => {
81
+ const large = image("large");
82
+ const small = image("small");
83
+ let finishLargeRead = (_dataUrl: string) => {};
84
+ const largeRead = new Promise<string>((resolve) => {
85
+ finishLargeRead = resolve;
86
+ });
87
+ vi.mocked(readFileAsDataUrl).mockImplementation(async (file) =>
88
+ file === large.file ? largeRead : "data:image/png;base64,c21hbGw=",
89
+ );
90
+
91
+ const serialized = serializeComposerImages([large, small], []);
92
+ finishLargeRead("data:image/png;base64,bGFyZ2U=");
93
+ expect((await serialized).map(({ id }) => id)).toEqual(["large", "small"]);
94
+ });
95
+
96
it("omits failed uncached reads while keeping successfully serialized images", async () => {
97
const a = image("a");
98
const b = image("b");
apps/web/src/components/chat/composerImagePersistence.ts
+5
-9
@@ -11,27 +11,23 @@ export async function serializeComposerImages(
11
const existingPersistedById = new Map(
12
persistedAttachments.map((attachment) => [attachment.id, attachment]),
13
);
14
- const stagedAttachmentById = new Map<string, PersistedComposerImageAttachment>();
15
- await Promise.all(
14
+ const staged = await Promise.all(
15
images.map(async (image) => {
16
try {
17
const dataUrl =
18
existingPersistedById.get(image.id)?.dataUrl ?? (await readFileAsDataUrl(image.file));
20
- stagedAttachmentById.set(image.id, {
19
+ return {
20
id: image.id,
21
name: image.name,
22
mimeType: image.mimeType,
23
sizeBytes: image.sizeBytes,
24
dataUrl,
25
...(image.source ? { source: image.source } : {}),
27
- });
26
+ };
27
} catch {
29
- const existingPersisted = existingPersistedById.get(image.id);
30
- if (existingPersisted) {
31
- stagedAttachmentById.set(image.id, existingPersisted);
32
- }
28
+ return existingPersistedById.get(image.id);
29
}
30
}),
31
);
36
- return Array.from(stagedAttachmentById.values());
32
+ return staged.filter((attachment) => attachment !== undefined);
33
}