fix(channels): fix optimistically insert attachments#1302
Conversation
synoet
commented
Feb 3, 2026
- attachments where previously not being optimistically inserted
Code reviewBug found: Optimistic attachments lose their association after message ID replacement In const newAttachments: Attachment[] = vars.attachments.map((a) => ({
id: crypto.randomUUID(),
channel_id: vars.channelId,
created_at: String(Date.now()),
message_id: vars.optimisticId, // <-- Uses optimistic ID
...a,
}));When the mutation succeeds, In
Result: Attachments will briefly show when the message is first sent, then disappear after the server responds, until the next cache refetch. Fix: Update return {
...prev,
messages: updatedMessages,
attachments: prev.attachments.map((a) =>
a.message_id === vars.optimisticId
? { ...a, message_id: vars.realId }
: a
),
}; |