# Inconsistent data being returned from Reactions to Comment Add and Remove Feature

**URL:** <https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185>\
**Category:** Web\
**Tags:** technical\
**Created:** [June 28, 2021, 5:54am UTC](https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185 "2021-06-28T05:54:44Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijanshs](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sijanshs](https://forum.social.plus/u/sijanshs)\
**Post date:** [June 28, 2021, 5:54am UTC](https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185/1 "2021-06-28T05:54:44Z")

</div>

SDK: ` "@amityco/js-sdk": "^5.1.0"`  
**strong text**  
Hey Team,

I am currently facing issue with Comment Add and remove Feature.

I am getting inconsistent data and **dataUpdated** is being fired multiple times with various inconsitent results, and the final result is still wrong.

**What do I mean by this?**  
For example if I like a post,i can see my reaction, but I decide to remove the like from the post, here is what happens:

1. i click the button on the post
2. it fires the CommentRepository.removeReaction(Id)
3. it fires up `dataUpdated` 3 times, and the final result will still have my Reaction on it.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/c6dedb22143732fb3707780474ef3acf101ad245.png)

And sometimes the data is inconsistent, I still can see my Reactions but the count and reactions array are empty as below

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/8a027add4acf767b41336868132f2099594e5f31.png)

Here is the relevant code I used, this is run in an isolated environment and no re-renders from parents:

```auto
  useEffect(() => {
    collection.current = CommentRepository.queryComments({
      referenceType: COMMENT_REFERENCE_TYPE,
      referenceId: post.id,
      last: currentLimit,
      isDeleted: false,
      filterByParentId: true,
    });

    setLoading(collection.current.loadingStatus === 'loading');

    collection.current.on('dataUpdated', (data) => {
      const curated = data.map(({ myReactions, reactions, reactionsCount }) => ({
        myReactions,
        reactions,
        reactionsCount,
      }));
      console.log('>>> dataUpdated', curated[0]);
      setComments(data); // reload comment table
      setHasMore(collection.current.hasMore);
      setLoading(false);
    });

    collection.current.on('dataError', (error) => {
      setLoading(false);
      if (error.message === 'EkoSDK: Some post not found') return;
      console.error('Comment LiveCollections can not query/get/sync data from server', { error });
    });

    return () => collection.current.dispose();
  }, [post, referenced]);

```

```auto
      const handleReaction = useCallback(
        async (reactionName) => {
            setIsProcessing(true);

            try {
              const addResponse = await CommentRepository.addReaction({
                commentId: amityContent.commentId,
                reactionName,
              });
              if (!addResponse) throw new Error('Cannot add Reaction');
              setReactionType(reactionName);

            } catch (e) {
              tracking.trackEvent({... });
          } finally {
...
       }
        },
        [isProcessing, amityContent, reactionType]
      );

      const handleRemoveReaction = useCallback(
        async (ev) => {
            setIsProcessing(true);
            try {
              const removeResponse = await CommentRepository.removeReaction({
                commentId: amityContent.commentId,
                reactionName: reactionType,
              });
              if (!removeResponse) throw new Error('Cannot remove Reaction');

             setReactionType('');
            } catch (e) {
              tracking.trackEvent({ 
                 ...
              });
            } finally {
                ...
            }
          }
        },
        [isProcessing, amityContent, reactionType]
      );

```

Please help provide some insight on this. We are currently blocked by not being able to display the reaction count and my reactions correctly.

Any suggestion or solution is much appreciated.  
Thanks

---

<div class="post-metadata">

**Author:** ![sijanshs](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sijanshs](https://forum.social.plus/u/sijanshs)\
**Post date:** [June 28, 2021, 6:05am UTC](https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185/2 "2021-06-28T06:05:42Z")

</div>

Just FYI, the issue is with only the comments, for posts everything is smooth so far

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [June 29, 2021, 2:42pm UTC](https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185/3 "2021-06-29T14:42:35Z")

</div>

Hi @sijanshs Thank you for the inquiry, we are investigating and update the information to you soon.

---

<div class="post-metadata">

**Author:** ![Julien](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Julien](https://forum.social.plus/u/Julien)\
**Post date:** [July 6, 2021, 12:19pm UTC](https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185/4 "2021-07-06T12:19:49Z")

</div>

Hello,

As seen together in our session, if you could provide a minimal reproductible case, that could help us into inquirying the issue.

You can provide either a git repository or a codesandbox url up to your liking.

---

<div class="post-metadata">

**Author:** ![sijanshs](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sijanshs](https://forum.social.plus/u/sijanshs)\
**Post date:** [July 8, 2021, 6:20am UTC](https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185/5 "2021-07-08T06:20:55Z")

</div>

Hi @Julien , thanks for checking up, i tried to test this in a isolated environment, and was not able to replicate it.  
I will get back if I am able to replicate.

---

<div class="post-metadata">

**Author:** ![sijanshs](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sijanshs](https://forum.social.plus/u/sijanshs)\
**Post date:** [July 8, 2021, 9:15am UTC](https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185/6 "2021-07-08T09:15:53Z")

</div>

However, i would like to know, is there some special conditions it is possible that the dataUpdated is triggered multiple times?  
Is it some way to debug if it is coming from the server ?

---

<div class="post-metadata">

**Author:** ![sijanshs](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sijanshs](https://forum.social.plus/u/sijanshs)\
**Post date:** [July 8, 2021, 9:22am UTC](https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185/7 "2021-07-08T09:22:19Z")

</div>

Here is some logs, for 1 Reaction Remove, could this help identify what might be causing the multiple trigger of data?

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/0d1ce4d48508903b470980a9a70bbd3a4d2a7be5.png)

---

<div class="post-metadata">

**Author:** ![Julien](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Julien](https://forum.social.plus/u/Julien)\
**Post date:** [July 9, 2021, 2:51am UTC](https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185/8 "2021-07-09T02:51:49Z")

</div>

Hey @sijanshs,

> is there some special conditions it is possible that the dataUpdated is triggered multiple times?

Reactions are handled optimistically for faster time to response, so you’ll have a first event emitted from client side, and a second one emitted from the response of server as confirmation.

> Is it some way to debug if it is coming from the server ?

It’s expected to have multiple events, so i’m not sure if that could help particularly identifying where it’s coming from.

> could this help identify what might be causing the multiple trigger of data?

Not really ; we’d need reproducible case to be able to pinpoint where it comes from.

---

<div class="post-metadata">

**Author:** ![Kamolla](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@Kamolla](https://forum.social.plus/u/Kamolla)\
**Post date:** [July 30, 2021, 8:35am UTC](https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185/9 "2021-07-30T08:35:23Z")

</div>

I’m also facing the same issue.

When I remove the reaction on comment using

```auto
 CommentRepository.removeReaction({
    commentId: 'Comment123',
    reactionName: 'like',
 })

```

I got multiple result (around 3 times) from the **dataUpdated** by

```auto
CommentRepository.queryComments({
  referenceType: 'content',
  referenceId: 'Reference123',
  last: 20,
  filterByParentId: true,
  isDeleted: false,
 });

```

And the reaction from result is incorrect and inconsistent.

1st result: { commentId: ‘Comment123’, myReactions: [], reactions: {}, reactionsCount: 0} (CORRECT)  
2nd result: { commentId: ‘Comment123’, myReactions: [“like”], reactions: {like: 1}, reactionsCount: 1}  
3rd result: { commentId: ‘Comment123’, myReactions: [“like”], reactions: {}, reactionsCount: 0}

in the end, my result got wrong data.

btw, if I reload or fetch again, the result from \*_dataUpdated_ is correct.

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [July 30, 2021, 3:58pm UTC](https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185/10 "2021-07-30T15:58:35Z")

</div>

Hi @Kamolla, thank you for the information.  
We will check again and update you soon.

---

<div class="post-metadata">

**Author:** ![Kamolla](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@Kamolla](https://forum.social.plus/u/Kamolla)\
**Post date:** [August 3, 2021, 2:52am UTC](https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185/11 "2021-08-03T02:52:29Z")

</div>

Any update for my comment?

---

<div class="post-metadata">

**Author:** ![Julien](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Julien](https://forum.social.plus/u/Julien)\
**Post date:** [August 6, 2021, 5:49am UTC](https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185/12 "2021-08-06T05:49:26Z")

</div>

Hello @Kamolla ,

We’ve acknowledged this as a bug and are addressing the issue. We’ll propose a fix in the coming days/weeks. I’ll update you once this properly published.

Thank you for your patience,  
J.

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [August 31, 2021, 12:06pm UTC](https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185/13 "2021-08-31T12:06:42Z")

</div>

Hi @Kamolla, please allow us to update you on this issue.  
We fixed it on SDK(web) version 5.4.3 and already released it last Friday(27/09/2021).

Sorry for the late update and thank you for your patience,

---

<div class="post-metadata">

**Author:** ![Kamolla](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@Kamolla](https://forum.social.plus/u/Kamolla)\
**Post date:** [September 14, 2021, 8:21am UTC](https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185/14 "2021-09-14T08:21:32Z")

</div>

Thank you for the updates.

After I upgraded SDK(web) to latest version 5.5.1.

Unfortunately, the issue is still happening. when user remove reaction on comment (Using CommentRepository.removeReaction() ).

Let’s me clarify there are 2 issues:

1. I got React re-render issue because after user clicking remove reaction, the comment has been sent 3 times by CommentRepository.queryComments() during on(‘dataUpdated’).

2.The result from on(‘dataUpdated’), each of them is inconsistent.

> 1st result: { commentId: ‘Comment123’, myReactions: [‘like’, ‘dislike’], reactions: { like: 1}, reactionsCount: 1}  
> 2nd result: { commentId: ‘Comment123’, myReactions: [‘like’, ‘dislike’], reactions: {}, reactionsCount: 0}  
> 3rd result: { commentId: ‘Comment123’, myReactions: [“like”], reactions: {}, reactionsCount: 0}

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [September 14, 2021, 8:40am UTC](https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185/15 "2021-09-14T08:40:23Z")

</div>

Hello @Kamolla thank you for informing us, we will check this case on our end and will get back to you asap when there is an update.

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [October 4, 2021, 4:21am UTC](https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185/16 "2021-10-04T04:21:32Z")

</div>

Hi @Kamolla the team is looking into this issue, we will update you once we receive an update from the team.

---

<div class="post-metadata">

**Author:** ![ralph\_tdg](https://avatars.discourse-cdn.com/v4/letter/r/f17d59/32.png) [@ralph\_tdg](https://forum.social.plus/u/ralph_tdg)\
**Post date:** [January 5, 2022, 3:26am UTC](https://forum.social.plus/t/inconsistent-data-being-returned-from-reactions-to-comment-add-and-remove-feature/185/17 "2022-01-05T03:26:07Z")

</div>

@SocialPlus_Support Do we have any update here? We tried with 5.8.0 but the results were still the same.
