-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix UI Not Updating Immediately After Pinning/Unpinning Messages #654
base: develop
Are you sure you want to change the base?
Conversation
@@ -91,10 +91,13 @@ const Message = ({ | |||
|
|||
const handlePinMessage = async (msg) => { | |||
const isPinned = msg.pinned; | |||
// Optimistically update the UI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this comment
Hey @smritidoneria! Although I understood your solution, but I am unable to figure out why this needs to be done manually. I think the best way would be if state updation triggers this action rather than setting this up optimistically. Do you know why the automatic updation is failing? |
hey @Barrylimarti , previously the problem was that the code is directly modifies the msg.pinned property without triggering a re-render of the component. In React, directly mutating an object does not cause the component to re-render. React only re-renders components when the state or props change. Re-rendering was only happening at refreshing. that is why the previous code was failing. so the solution for this comes out to be either use react states to manage the pinning of the message or optimistically update the ui. In my judgement, 2nd option was good to look forward to. |
Yeah that's correct ! But how exactly does this new code work ? I think here also, you're updating msg.pinned property directly here as well. |
Okay, but if you see the case of starring the message, it does not require this manual update though. Isn't it strange? If there's a call to the starring api it triggers the re-render but not in the case of the pinning api? |
Hey @Barrylimarti @Spiral-Memory , Sorry for the late response. Actually , The handleStarMessage function does not directly update the msg.starred property. Instead, it relies on the asynchronous operation RCInstance.starMessage or RCInstance.unstarMessage to update the state. This means that the state management for starred messages is handled elsewhere, likely in a parent component or a global state management solution (e.g., Redux, Context API). But the handlePinMessage function directly reads the msg.pinned property but does not update it directly. |
@smritidoneria Yes, that's exactly my point. But unpinning works well right? That means the same state management operations that is there for starred messages is there for pinning also but there's some bug while pinning it not while unpinning it. Hence, I think we should try to find that bug first at the state management level.
Also, I don't think this is the case as unpinning means updating the msg.pinned property to false, which is anyways happening. |
Did you guys figured out, what's the actual reason behind this ? |
hey @Spiral-Memory ,yes, it figured it out. |
We now have two possible approaches to address this issue: |
Brief Title
This PR addresses the issue where the UI does not immediately reflect the change when pinning or unpinning a message. The pin icon remains unchanged until the page is refreshed, and the system allows pinning the same message multiple times without updating the UI to show the message is already pinned.
Acceptance Criteria fulfillment
Fixes #653
Video/Screenshots
Screen.Recording.2024-11-02.at.4.58.44.PM.mov
PR Test Details
Note: The PR will be ready for live testing at https://rocketchat.github.io/EmbeddedChat/pulls/pr-<pr_number> after approval.