Skip to content

fix(channels): fix optimistically insert attachments#1302

Merged
synoet merged 3 commits intomainfrom
synoet/optimistic-attachments
Feb 3, 2026
Merged

fix(channels): fix optimistically insert attachments#1302
synoet merged 3 commits intomainfrom
synoet/optimistic-attachments

Conversation

@synoet
Copy link
Copy Markdown
Contributor

@synoet synoet commented Feb 3, 2026

  • attachments where previously not being optimistically inserted

@synoet synoet requested a review from a team as a code owner February 3, 2026 21:14
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 3, 2026

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Feb 3, 2026

Code review

Bug found: Optimistic attachments lose their association after message ID replacement

In js/app/packages/queries/channel/message.ts:77-83, the optimistic attachments are created with message_id: vars.optimisticId:

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, replaceOptimisticMessage is called, which updates the message's id from optimisticId to realId. However, the replaceOptimisticMessage function only updates messages and does NOT update the attachments' message_id field.

In MessageContainer.tsx:299, attachments are filtered by a.message_id === message.id, which will fail after ID replacement because:

  • message.id = realId (new server-assigned ID)
  • attachment.message_id = optimisticId (old ID that was never updated)

Result: Attachments will briefly show when the message is first sent, then disappear after the server responds, until the next cache refetch.

Fix: Update replaceOptimisticMessage to also replace the message_id for attachments:

return {
  ...prev,
  messages: updatedMessages,
  attachments: prev.attachments.map((a) =>
    a.message_id === vars.optimisticId
      ? { ...a, message_id: vars.realId }
      : a
  ),
};

@macro-inc macro-inc deleted a comment from claude bot Feb 3, 2026
@synoet synoet merged commit 0fd0e2d into main Feb 3, 2026
21 checks passed
@synoet synoet deleted the synoet/optimistic-attachments branch February 3, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant