stream-chat-react icon indicating copy to clipboard operation
stream-chat-react copied to clipboard

bug: ChannelPreview problems

Open szuperaz opened this issue 3 years ago • 3 comments

Describe the bug

  • lastMessage variable is updated for message.update and message.delete events without checking if the actual latest message was updated/deleted -> if we update/delete and older message then lastMessage will have an invalid value (see https://github.com/GetStream/stream-chat-react/issues/1736)
  • latestMessage variable uses channel.state.messages to grab the latest message, this could cause problems if an older message set is loaded inside the message list -> we should use channel.state.latestMessages
  • not a bug, but the naming is confusing lastMessage refers to the last message object, and latestMessage refers to the text that should be displayed in the channel preview, probably this could be called something like lastMessagePreview and latestMessage could be deprecated

To Reproduce

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. 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.

szuperaz avatar Sep 07 '22 13:09 szuperaz

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.

arnautov-anton avatar Sep 07 '22 15:09 arnautov-anton

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?

szuperaz avatar Sep 07 '22 16:09 szuperaz

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

arnautov-anton avatar Sep 07 '22 16:09 arnautov-anton