Skip to content
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

Encountered two children with the same key in channel list #901

Closed
philippeauriach opened this issue Oct 4, 2021 · 5 comments
Closed

Encountered two children with the same key in channel list #901

philippeauriach opened this issue Oct 4, 2021 · 5 comments
Assignees
Labels
Needs More Information Further information needed from the requester Needs Triaging

Comments

@philippeauriach
Copy link

philippeauriach commented Oct 4, 2021

Describe the bug
A user with a lot of channels (> 50) gets weird channels displayed (using ChannelList) after scrolling a bit (he reported the bug as "conversation duplicated). Investigating in dev mode, it appears that channels pagination is working weirdly, and returning conversation already present, resulting in duplicates in the displayed list. I added logs in "usePaginatedChannels" line 90 (setNewChannels) and it shows the duplicated results after having scrolled a bit (starting on the third or fourth call). I tried with a limit of 5, 10 and 30, and everytime I end up with duplicates after having scrolled.

Dev environment info (please complete/provide the following information):

const sort: ChannelSort = { last_message_at: -1 }
const options: ChannelOptions = { limit: 30 }

(I noticed that if I set an empty sort object, the bug does not appear)

  • Package version stream-chat@4.2.0 stream-chat-react-native@3.8.3
  • react-native@0.64.1
  • Device/Emulator (android/ios) and OS version iOS and Android

To Reproduce
Steps to reproduce the behavior:

Create an UI using provided chat components, with a user having a lot of channels. Scroll for a bit, in dev mode you'll see the react warnings.

Expected behavior
A clear and concise description of what you expected to happen.

Additional context
Add any other context about the problem here.

Screenshots
If applicable, add screenshots to help explain your problem.

gz#15572

@vishalnarkhede
Copy link
Contributor

vishalnarkhede commented Oct 5, 2021

Hey @philippeauriach We have seen this issue previously, and the root cause in most of the cases was the sort. If the last_messages_at field on channel is null (basically empty channel), then our backend won't be able to sort those channels appropriately. So you should

  • EITHER replace last_message_at sort param with { last_updated: -1 }, which is also a default sort for channels api. So for this case you simply remove the sort prop from ChannelList component
  • OR add secondary sort parameter to sort null values of last_message_at field, as shown in following code snippet:
sort={[
 { last_message_at: -1 },
 { cid: -1 }
]}

Please let me know if this helps and works :)

@vishalnarkhede vishalnarkhede added Needs Triaging Needs More Information Further information needed from the requester labels Oct 5, 2021
@philippeauriach
Copy link
Author

Hello @vishalnarkhede , we ended up removing the sort and it is working fine. Does the "last_updated" is also updated when a new message is sent in the channel ?

@vishalnarkhede
Copy link
Contributor

Hey @philippeauriach yes, thats correct.

@vishalnarkhede
Copy link
Contributor

I am closing this issue for now, but let us know if you have any more questions.

@philippeauriach
Copy link
Author

Perfect, thanks for the help !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Information Further information needed from the requester Needs Triaging
Projects
None yet
Development

No branches or pull requests

2 participants