App icon indicating copy to clipboard operation
App copied to clipboard

iOS - Chat - User icon flickers when sending a message

Open kavimuru opened this issue 5 years ago • 58 comments

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:

  1. Launch the app and Log in
  2. On a conversation, click on the + button in the compose box
  3. 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:

View all open jobs on Upwork

kavimuru avatar Jul 24 '21 04:07 kavimuru

: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:

  1. Identify the pull request that introduced this issue and revert it.
  2. Find someone who can quickly fix the issue.
  3. Fix the issue yourself.

OSBotify avatar Jul 24 '21 04:07 OSBotify

Triggered auto assignment to @Dal-Papa (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

MelvinBot avatar Jul 24 '21 04:07 MelvinBot

Triggered auto assignment to @mallenexpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

MelvinBot avatar Jul 26 '21 07:07 MelvinBot

@kavimuru is this still a deploy blocker?

mallenexpensify avatar Jul 26 '21 17:07 mallenexpensify

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.

isagoico avatar Jul 26 '21 18:07 isagoico

https://www.upwork.com/jobs/~01ccf19eee15ac9c94

mallenexpensify avatar Jul 26 '21 20:07 mallenexpensify

Triggered auto assignment to @thienlnam (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.

MelvinBot avatar Jul 26 '21 20:07 MelvinBot

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

aliabbasmalik8 avatar Jul 26 '21 21:07 aliabbasmalik8

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>

mananjadhav avatar Jul 26 '21 22:07 mananjadhav

@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?

thienlnam avatar Jul 26 '21 22:07 thienlnam

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

aliabbasmalik8 avatar Jul 26 '21 23:07 aliabbasmalik8

@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

mananjadhav avatar Jul 27 '21 14:07 mananjadhav

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

arpitdeveloper avatar Jul 27 '21 14:07 arpitdeveloper

@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

thienlnam avatar Jul 27 '21 17:07 thienlnam

@arpitdeveloper Unfortunately another contributor got to that conclusion first, but thank you for your interest!

thienlnam avatar Jul 27 '21 17:07 thienlnam

@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 avatar Jul 27 '21 17:07 parasharrajat

@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

thienlnam avatar Jul 27 '21 17:07 thienlnam

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.

parasharrajat avatar Jul 27 '21 17:07 parasharrajat

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 avatar Jul 28 '21 17:07 AlfredoAlc

@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?

rdjuric avatar Jul 28 '21 17:07 rdjuric