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 25, 07:30 UTC
fix(web): avoid false draft attachment persistence warnings (#1153)
shivam committed
Mar 24, 2026 at 05:40 UTC
e11fb6e778456a98e0066894bfb572864f98bb20
1 file changed
+48
-26
apps/web/src/composerDraftStore.ts
+48
-26
@@ -846,6 +846,53 @@ function readPersistedAttachmentIdsFromStorage(threadId: ThreadId): string[] {
846
}
847
}
848
849
+function verifyPersistedAttachments(
850
+ threadId: ThreadId,
851
+ attachments: PersistedComposerImageAttachment[],
852
+ set: (
853
+ partial:
854
+ | ComposerDraftStoreState
855
+ | Partial<ComposerDraftStoreState>
856
+ | ((
857
+ state: ComposerDraftStoreState,
858
+ ) => ComposerDraftStoreState | Partial<ComposerDraftStoreState>),
859
+ replace?: false,
860
+ ) => void,
861
+): void {
862
+ let persistedIdSet = new Set<string>();
863
+ try {
864
+ composerDebouncedStorage.flush();
865
+ persistedIdSet = new Set(readPersistedAttachmentIdsFromStorage(threadId));
866
+ } catch {
867
+ persistedIdSet = new Set();
868
+ }
869
+ set((state) => {
870
+ const current = state.draftsByThreadId[threadId];
871
+ if (!current) {
872
+ return state;
873
+ }
874
+ const imageIdSet = new Set(current.images.map((image) => image.id));
875
+ const persistedAttachments = attachments.filter(
876
+ (attachment) => imageIdSet.has(attachment.id) && persistedIdSet.has(attachment.id),
877
+ );
878
+ const nonPersistedImageIds = current.images
879
+ .map((image) => image.id)
880
+ .filter((imageId) => !persistedIdSet.has(imageId));
881
+ const nextDraft: ComposerThreadDraftState = {
882
+ ...current,
883
+ persistedAttachments,
884
+ nonPersistedImageIds,
885
+ };
886
+ const nextDraftsByThreadId = { ...state.draftsByThreadId };
887
+ if (shouldRemoveDraft(nextDraft)) {
888
+ delete nextDraftsByThreadId[threadId];
889
+ } else {
890
+ nextDraftsByThreadId[threadId] = nextDraft;
891
+ }
892
+ return { draftsByThreadId: nextDraftsByThreadId };
893
+ });
894
+}
895
+
896
function hydreatePersistedComposerImageAttachment(
897
attachment: PersistedComposerImageAttachment,
898
): File | null {
@@ -1662,32 +1709,7 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
1709
return { draftsByThreadId: nextDraftsByThreadId };
1710
});
1711
Promise.resolve().then(() => {
1665
- const persistedIdSet = new Set(readPersistedAttachmentIdsFromStorage(threadId));
1666
- set((state) => {
1667
- const current = state.draftsByThreadId[threadId];
1668
- if (!current) {
1669
- return state;
1670
- }
1671
- const imageIdSet = new Set(current.images.map((image) => image.id));
1672
- const persistedAttachments = attachments.filter(
1673
- (attachment) => imageIdSet.has(attachment.id) && persistedIdSet.has(attachment.id),
1674
- );
1675
- const nonPersistedImageIds = current.images
1676
- .map((image) => image.id)
1677
- .filter((imageId) => !persistedIdSet.has(imageId));
1678
- const nextDraft: ComposerThreadDraftState = {
1679
- ...current,
1680
- persistedAttachments,
1681
- nonPersistedImageIds,
1682
- };
1683
- const nextDraftsByThreadId = { ...state.draftsByThreadId };
1684
- if (shouldRemoveDraft(nextDraft)) {
1685
- delete nextDraftsByThreadId[threadId];
1686
- } else {
1687
- nextDraftsByThreadId[threadId] = nextDraft;
1688
- }
1689
- return { draftsByThreadId: nextDraftsByThreadId };
1690
- });
1712
+ verifyPersistedAttachments(threadId, attachments, set);
1713
});
1714
},
1715
clearComposerContent: (threadId) => {