stream-chat-react
stream-chat-react copied to clipboard
bug: ChannelPreview problems
Describe the bug
lastMessagevariable is updated formessage.updateandmessage.deleteevents without checking if the actual latest message was updated/deleted -> if we update/delete and older message thenlastMessagewill have an invalid value (see https://github.com/GetStream/stream-chat-react/issues/1736)latestMessagevariable useschannel.state.messagesto grab the latest message, this could cause problems if an older message set is loaded inside the message list -> we should usechannel.state.latestMessages- not a bug, but the naming is confusing
lastMessagerefers to the last message object, andlatestMessagerefers to the text that should be displayed in the channel preview, probably this could be called something likelastMessagePreviewandlatestMessagecould be deprecated
To Reproduce
Steps to reproduce the behavior:
- Go to '...'
- Click on '....'
- Scroll down to '....'
- See error
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Package version
- stream-chat-react:
- stream-chat-css:
- stream-chat-js:
Desktop (please complete the following information):
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
Smartphone (please complete the following information):
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
Additional context
Add any other context about the problem here.
So for the issue #1736 - we have two properties for the ChannelPreview component; lastMessage which is being updated on every message.add, message.delete and message.update event but is not being utilised within the actual Preview UI component (or anywhere else I think, not sure what's it for) and then there's a latestMessage (the naming is a bit misleading, since it's not a message object) which is generated by the getLatestMessagePreview function.
I checked the ChannelPreviewMessenger component, and it doesn't use lastMessage, not sure if we have any other component, and I wasn't able to reproduce the described behavior. I think they might use a custom component that relies on lastMessage?
Here's the reproduction with logging but since it's not being used anywhere you can't spot any visual changes in the application. We could probably document this behaviour and explain what this property could be used for or just deprecate it altogether. Also - either rename latestMessage to latestMessagePreview or pass down the latest message object, up to a debate - either way a breaking change I think.
https://user-images.githubusercontent.com/43254280/188931001-5e910a40-26c8-4df7-90ce-607c8e7b13c0.mov