The best way to control Claude Code, Codex and more from any computer or phone
fix(web): keep file uploads when returning a draft to its environment (#36572)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 14, 2026 at 09:36 UTC
3fe0fbb69f448b818889cf6977a6204dfe1030fe
2 files changed
+51
-22
apps/web/src/lib/attachmentUploadQueue.test.ts
+49
-22
@@ -1,4 +1,4 @@
1
-import { EnvironmentId } from "@t3tools/contracts";
1
+import { EnvironmentId, ProjectId } from "@t3tools/contracts";
2
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
3
import { Atom, AsyncResult } from "effect/reactivity";
4
import { appAtomRegistry } from "../rpc/atomRegistry";
@@ -640,27 +640,54 @@ describe("attachmentUploadQueue", () => {
640
);
641
});
642
643
- it("restores the previous environment after a replacement upload fails", async () => {
644
- const image = makeImage("image-move");
645
- startAttachmentUpload({ environmentId: firstEnvironment, image });
646
- await Promise.resolve();
647
- let settled = awaitAttachmentUploads([image.id]);
648
- TestXmlHttpRequest.requests[0]!.complete();
649
- await settled;
650
-
651
- startAttachmentUpload({ environmentId: secondEnvironment, image });
652
- await Promise.resolve();
653
- settled = awaitAttachmentUploads([image.id]);
654
- TestXmlHttpRequest.requests[1]!.complete(500);
655
- await settled;
656
-
657
- startAttachmentUpload({ environmentId: firstEnvironment, image });
658
- expect(readAttachmentUpload(image.id)).toMatchObject({
659
- status: "ready",
660
- environmentId: firstEnvironment,
661
- attachmentId: "pending-environment-1-image-move.png",
662
- });
663
- });
643
+ it.each(["image", "file"] as const)(
644
+ "restores the previous environment after a replacement upload fails: %s",
645
+ async (kind) => {
646
+ const draftId = DraftId.make("draft-environment-roundtrip");
647
+ const store = useComposerDraftStore.getState();
648
+ const image = kind === "image" ? makeImage("image-move") : makeFile("file-move");
649
+ const moveDraftTo = (environmentId: EnvironmentId) => {
650
+ store.setProjectDraftThreadId(
651
+ { environmentId, projectId: ProjectId.make("project") },
652
+ draftId,
653
+ );
654
+ startAttachmentUpload({ environmentId, image, draftTarget: draftId });
655
+ };
656
+ try {
657
+ if (image.type === "file") store.addFiles(draftId, [image]);
658
+ moveDraftTo(firstEnvironment);
659
+ await Promise.resolve();
660
+ let settled = awaitAttachmentUploads([image.id]);
661
+ TestXmlHttpRequest.requests[0]!.complete();
662
+ await settled;
663
+
664
+ moveDraftTo(secondEnvironment);
665
+ await Promise.resolve();
666
+ settled = awaitAttachmentUploads([image.id]);
667
+ TestXmlHttpRequest.requests[1]!.complete(500);
668
+ await settled;
669
+
670
+ moveDraftTo(firstEnvironment);
671
+ const attachmentId = `pending-environment-1-${image.name}`;
672
+ expect(readAttachmentUpload(image.id)).toMatchObject({
673
+ status: "ready",
674
+ environmentId: firstEnvironment,
675
+ attachmentId,
676
+ });
677
+ if (image.type === "file") {
678
+ expect(store.getComposerDraft(draftId)?.files).toMatchObject([
679
+ {
680
+ id: image.id,
681
+ uploadedAttachmentId: attachmentId,
682
+ uploadEnvironmentId: firstEnvironment,
683
+ },
684
+ ]);
685
+ }
686
+ } finally {
687
+ store.clearDraftThread(draftId);
688
+ }
689
+ },
690
+ );
691
692
it("does not let stalled uploads block another environment", async () => {
693
const images = ["image-a", "image-b", "image-c", "image-d"].map(makeImage);
apps/web/src/lib/attachmentUploadQueue.ts
+2
@@ -422,6 +422,8 @@ export function startAttachmentUpload(input: {
422
deletePendingUpload(existing.environmentId, existing.attachmentId);
423
}
424
setUploadState(input.image.id, existing.previous);
425
+ // Retargeting a scratch draft cleared the file's upload stamp; restore it for reloads.
426
+ stampDraftFileUpload(input, existing.previous.attachmentId);
427
return;
428
}
429