iOS - Chat - User icon flickers when sending a message
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Action Performed:
- Launch the app and Log in
- On a conversation, click on the + button in the compose box
- Send a message
Expected Result:
When sending the message the user icon shouldn't flicker
Actual Result:
When sending the message the user icon flickers
Workaround:
Unknown
Platform:
Where is this issue occurring?
- [ ] Web
- [x] iOS
- [ ] Android
- [ ] Desktop App
- [ ] Mobile Web
Version Number: 1.0.80-0 Logs: https://stackoverflow.com/c/expensify/questions/4856 Notes/Photos/Videos:
https://user-images.githubusercontent.com/43996225/126857477-ee593723-c222-449c-bc5a-011c4f5bc7af.mp4
Expensify/Expensify Issue URL:
:wave: Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open StagingDeployCash deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:
- Identify the pull request that introduced this issue and revert it.
- Find someone who can quickly fix the issue.
- Fix the issue yourself.
Triggered auto assignment to @Dal-Papa (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.
Triggered auto assignment to @mallenexpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.
@kavimuru is this still a deploy blocker?
Mmm I'm not able to reproduce consistently between several chats. I would say it's a 3/5 times. I also re checked this on production and found the same behaviour. Will remove the deploy locker label.
https://www.upwork.com/jobs/~01ccf19eee15ac9c94
Triggered auto assignment to @thienlnam (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.
PROPOSAL
It can be fixed by adding keyExtractor in FlatList like this way keyExtractor={item => item.index}
https://github.com/Expensify/App/blob/3d351694080b0c0d448e9d140d122de585eddd27/src/components/InvertedFlatList/BaseInvertedFlatList.js#L142-L158
OR can update keyExtractor here
https://github.com/Expensify/App/blob/001f285d935b0edf77b26c7097205339cce89858/src/pages/home/report/ReportActionsView.js#L410
Thanks
I can see that keyExtractor is already added to ReportActionsView. What is happening is the image is getting downloaded again when you're posting the message.
Proposal:
Can be resolved by replacing the default Image with RNFastImage
<View pointerEvents="none" style={this.props.containerStyles}>
{this.props.isDefaultChatRoom
? <RoomAvatar avatarStyle={imageStyle} isArchived={this.props.isArchivedRoom} />
: <Image source={{uri: this.props.source}} style={imageStyle} />}
</View>
@aliabbasmalik8 Thanks for the proposal, could you explain why that is the problem?
@mananjadhav Are we seeing another network request for the image when the message is sent?
ISSUE:
there is an issue on keyExtractor so the icons flickers on state update.
https://github.com/Expensify/App/blob/001f285d935b0edf77b26c7097205339cce89858/src/pages/home/report/ReportActionsView.js#L410
we can fix by updating keyExtractor like this way
keyExtractor={item => item.index.toString()}
Thanks
After Updating keyExtractor
https://user-images.githubusercontent.com/31027036/127396962-11bd526a-408f-46ea-9327-0ad3d5354e7f.mov
Issue Reproducing (Without updating keyExtractor)
https://user-images.githubusercontent.com/31027036/127397015-9efa502e-365e-44c3-865f-76004154df00.mov
cache-control also helpful for image performance perspective for ios
@thienlnam Yes. Attaching the video for the same. Also, we're already passing keyExtractor. It won't solve the image caching issue.
I know for sure that the RN Fast Image can resolve this for us.
https://user-images.githubusercontent.com/3069065/127173966-63ae7eb3-546f-41aa-b564-83c3bae88e1e.mov
In src/components/InvertedFlatList/BaseInvertedFlatList.js we add keyExtractor={item => item.index} in flatlist or In src/pages/home/report/ReportActionsView.js replace keyExtractor with keyExtractor={item => item.index} in InvertedFlatList
@mananjadhav You have the Disable cache enabled so that isn't really a true test as to whether or not there is another image request. I tested it myself and the avatar images get cached on web where they have the correct image headers set.
@aliabbasmalik8 Going to give you the 🟢 for the proposal, we'll see if that fixes it
@arpitdeveloper Unfortunately another contributor got to that conclusion first, but thank you for your interest!
@thienlnam we already have keyExtractor for ChatList. It's the first thing anybody will do with the most expensive list on the App so we have not missed this. Just bringing you more context here.
https://github.com/Expensify/App/blob/e043ac21f3706baed9b12fb9c7bd2b5ecbb55540/src/pages/home/report/ReportActionsView.js#L410
@parasharrajat Thanks for the catch - I should have checked that first. Going to unassign @aliabbasmalik8.
I still am not sure that image caching is the issue here since we are already caching those avatar thumbnails
I still am not sure that image caching is the issue here since we are already caching those avatar thumbnails
I also think the same. I'll try to test this, if possible.
PROPOSAL
I have been checking the code, and the problem it's in the keyExtractor in ReportActionsView.
The key for each item is a combination of action.sequenceNumber and action.clientID.
https://github.com/Expensify/App/blob/b964c89bb2f010299cccd1cfa6263a00348eaf5f/src/pages/home/report/ReportActionsView.js#L407-L410
The issue stars when merged onto Onix, the sequenceNumber is a temporal optimisticReportActionID, quoting the comments of why this is used.. "We do this because it's not safe to assume that this will use the very next sequenceNumber".
https://github.com/Expensify/App/blob/de5b024fca24bc18fad99e583961035a87a8b950/src/libs/actions/Report.js#L1044-L1075
But once the ReportAction is created in the server, the sequenceNumber is modified with the actual number, and then updated in Onix.
https://github.com/Expensify/App/blob/de5b024fca24bc18fad99e583961035a87a8b950/src/libs/actions/Report.js#L1077-L1098
The change of that sequenceNumber causes to change the key of the item, and that causes to re render that last message sent, hence the flickering in the image.
A solution to avoid re rendering items could be to only use clientID for the key, and to prevent any issues in case the clientID its the same for two different items, it could be used the combination of clientID and index.
@AlfredoAlc Just curious, on the video in the issue the Avatar also flickers when we receive a message, and the sequence number of a received messaged is not optimistic (we receive the final sequenceNumber from the API).
So since the sequenceNumber doesn't change, the key for a received message shouldn't change either but the Avatar still flickers, do you know why?