Skip to content

Commit

Permalink
Bug fix: Some mentionables do not get deleted when multiple items are…
Browse files Browse the repository at this point in the history
… deleted at once. (#29)
  • Loading branch information
glowingjade authored Oct 16, 2024
1 parent 5e6d05e commit 2496718
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/chat-view/chat-input/ChatUserInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const ChatUserInput = forwardRef<ChatUserInputRef, ChatUserInputProps>(
const handleMentionNodeMutation = (
mutations: NodeMutations<MentionNode>,
) => {
const destroyedMentionableIds: string[] = []
mutations.forEach((mutation) => {
if (mutation.mutation !== 'destroyed') return

Expand All @@ -123,9 +124,13 @@ const ChatUserInput = forwardRef<ChatUserInputRef, ChatUserInputProps>(

if (!nodeWithSameId) {
// remove mentionable only if it's not present in the editor state
setMentionables(mentionables.filter((m) => m.id !== id))
destroyedMentionableIds.push(id)
}
})

setMentionables(
mentionables.filter((m) => !destroyedMentionableIds.includes(m.id)),
)
}

const handleMentionableDelete = (mentionable: Mentionable) => {
Expand Down

0 comments on commit 2496718

Please sign in to comment.