Skip to content

Commit 073734c

Browse files
authored
fix(web): failed attachment uploads no longer block sending (pingdotgg#20737)
1 parent 3b41d5f commit 073734c

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,9 @@ import { useComposerHandleContext } from "../composerHandleContext";
517517
import {
518518
awaitAttachmentUploads,
519519
getUploadedAttachments,
520+
readAttachmentUpload,
520521
releaseDraftAttachments,
522+
retryAttachmentUpload,
521523
startAttachmentUpload,
522524
} from "../lib/attachmentUploadQueue";
523525
import { sanitizeThreadErrorMessage } from "~/rpc/transportError";
@@ -6436,7 +6438,11 @@ export default function ChatView(props: ChatViewProps) {
64366438
: supportsAttachmentUploads;
64376439
if (turnUsesAttachmentUploads && composerAttachmentsSnapshot.length > 0) {
64386440
for (const attachment of composerAttachmentsSnapshot) {
6439-
startAttachmentUpload({
6441+
const upload =
6442+
readAttachmentUpload(attachment.id)?.status === "failed"
6443+
? retryAttachmentUpload
6444+
: startAttachmentUpload;
6445+
upload({
64406446
environmentId,
64416447
image: attachment,
64426448
draftTarget: composerDraftTarget,

‎apps/web/src/lib/attachmentUploadState.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe("attachmentUploadBlockReason", () => {
3737
).toBe("Attachments still uploading");
3838
});
3939

40-
it("asks the user to retry or remove failed uploads", () => {
40+
it("leaves send enabled for failed uploads so sending can retry them", () => {
4141
expect(
4242
attachmentUploadBlockReason({
4343
imageIds: ["image-1"],
@@ -46,7 +46,7 @@ describe("attachmentUploadBlockReason", () => {
4646
"image-1": { status: "failed", environmentId, reason: "Upload failed" },
4747
},
4848
}),
49-
).toBe("Retry or remove the failed attachment");
49+
).toBeNull();
5050
});
5151

5252
it("does not accept an upload from another environment", () => {

‎apps/web/src/lib/attachmentUploadState.ts‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,16 @@ export function attachmentUploadBlockReason(input: {
3232
readonly environmentId: EnvironmentId;
3333
}): string | null {
3434
let pending = 0;
35-
let failed = 0;
3635

3736
for (const imageId of input.imageIds) {
3837
const upload = input.uploadsByImageId[imageId];
39-
if (upload?.status === "failed" && upload.environmentId === input.environmentId) {
40-
failed += 1;
41-
} else if (upload?.status !== "ready" || upload.environmentId !== input.environmentId) {
38+
// Send retries failed uploads, so they must not disable it.
39+
if (upload?.status === "failed" && upload.environmentId === input.environmentId) continue;
40+
if (upload?.status !== "ready" || upload.environmentId !== input.environmentId) {
4241
pending += 1;
4342
}
4443
}
4544

46-
if (failed > 0) {
47-
return failed === 1
48-
? "Retry or remove the failed attachment"
49-
: "Retry or remove the failed attachments";
50-
}
5145
if (pending > 0) {
5246
return pending === 1 ? "Attachment still uploading" : "Attachments still uploading";
5347
}

0 commit comments

Comments
 (0)