Skip to content

Commit 3b5b338

Browse files
fix(web): ignore compression errors for removed images
1 parent bd8533b commit 3b5b338

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

‎apps/web/src/components/chat/useComposerAttachmentIntake.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ export function useComposerAttachmentIntake(input: {
258258
if (questionAttachmentTarget)
259259
changeQuestionAttachmentPreparation(questionAttachmentTarget, acceptedImages.length);
260260
const compressed: { id: string; file: File }[] = [];
261-
let compressionError: string | null = null;
261+
// Keyed by image so a failure whose tile was removed (even mid-compression) is not reported.
262+
const compressionErrors = new Map<string, string>();
262263
for (const { id, file } of preparingImages) {
263264
// Removed from the strip while an earlier image was compressing.
264265
if (!isPreparingComposerImage(attachmentTargetKey, id)) continue;
@@ -269,10 +270,12 @@ export function useComposerAttachmentIntake(input: {
269270
PROVIDER_SEND_TURN_MAX_IMAGE_BYTES,
270271
).catch(() => ({ ok: false, reason: "unreadable" }) as const);
271272
if (!result.ok) {
272-
compressionError =
273+
compressionErrors.set(
274+
id,
273275
result.reason === "unreadable"
274276
? `'${file.name}' could not be read as an image.`
275-
: `'${file.name}' is too large to attach, even after compression.`;
277+
: `'${file.name}' is too large to attach, even after compression.`,
278+
);
276279
continue;
277280
}
278281
inheritComposerImageThumbnail(file, result.file);
@@ -321,7 +324,11 @@ export function useComposerAttachmentIntake(input: {
321324
// now other work (a failed send, an overlapping paste) may have set a
322325
// thread error this call knows nothing about, and clearing it would
323326
// swallow that message.
324-
if (compressionError !== null) {
327+
const compressionError = [...compressionErrors]
328+
.filter(([id]) => stillPreparingIds.has(id))
329+
.map(([, message]) => message)
330+
.at(-1);
331+
if (compressionError !== undefined) {
325332
setThreadError(threadId, compressionError);
326333
}
327334
return insertedAny;

0 commit comments

Comments
 (0)