From 619decd25389065ce828e1f45ff2b595edf40363 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Wed, 1 Mar 2023 13:24:11 +0200 Subject: [PATCH] Fix potential reaction crash (#7172) --- .../post_list/post/body/reactions/reactions.tsx | 10 +++++----- app/utils/emoji/helpers.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/components/post_list/post/body/reactions/reactions.tsx b/app/components/post_list/post/body/reactions/reactions.tsx index 8bbd1a55c..d43955545 100644 --- a/app/components/post_list/post/body/reactions/reactions.tsx +++ b/app/components/post_list/post/body/reactions/reactions.tsx @@ -86,11 +86,11 @@ const Reactions = ({currentUserId, canAddReaction, canRemoveReaction, disabled, if (reaction) { const emojiAlias = getEmojiFirstAlias(reaction.emojiName); if (acc.has(emojiAlias)) { - const rs = acc.get(emojiAlias); + const rs = acc.get(emojiAlias)!; // eslint-disable-next-line max-nested-callbacks - const present = rs!.findIndex((r) => r.userId === reaction.userId) > -1; + const present = rs.findIndex((r) => r.userId === reaction.userId) > -1; if (!present) { - rs!.push(reaction); + rs.push(reaction); } } else { acc.set(emojiAlias, [reaction]); @@ -105,7 +105,7 @@ const Reactions = ({currentUserId, canAddReaction, canRemoveReaction, disabled, }, new Map()); return {reactionsByName, highlightedReactions}; - }, [sortedReactions]); + }, [sortedReactions, reactions]); const handleAddReactionToPost = (emoji: string) => { addReaction(serverUrl, postId, emoji); @@ -178,7 +178,7 @@ const Reactions = ({currentUserId, canAddReaction, canRemoveReaction, disabled, return ( { +export const getEmojiFirstAlias = (emoji: string): string => { return getEmojiByName(emoji, [])?.short_names?.[0] || emoji; };