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

bug: Attachments get re-mounted on hover

Open rvanlaarhoven opened this issue 2 years ago • 2 comments

Describe the bug

Attachments get a new key on every render whenever it does not have an id due to the introduction of nanoid. This is causing the attachment component (e.g. ImageAttachment) to remount on every prop change.

See the code here: https://github.com/GetStream/stream-chat-react/blob/develop/src/components/Attachment/utils.tsx#L103 Which got introduced by this commit: https://github.com/GetStream/stream-chat-react/commit/39cedcb8d0821e4bb6e8061349ae52132aa32c45

I'm not sure how the attachment id is supposed to work, since in our case attachments never receive an id. Is Stream supposed to generate the id and return it with the messages? Anyway, since our attachments have no id's, they always falls back to the nanoid. Once we hover over the attachment, it's causing a prop change which in turn generates a new unique key and forcing the component to remount.

Expected behavior

The Attachment component key should not change between renders and should be unique for an attachment to avoid unexpected un/remounts

Package version

  • stream-chat-react: 9.1.3
  • stream-chat-js: 6.6.0

Desktop (please complete the following information):

  • OS: macOS 12.4
  • Browser: Brave

rvanlaarhoven avatar Jun 20 '22 13:06 rvanlaarhoven

Hey @rvanlaarhoven, thank you for your submission! There's currently a refactor in the works that should address this issue, can't give you exact ETA though.

arnautov-anton avatar Jun 20 '22 21:06 arnautov-anton

No problem! I reverted to 8.1.3 for now. I'll keep an eye out for new releases

rvanlaarhoven avatar Jun 21 '22 06:06 rvanlaarhoven

Sorry it took so long, @rvanlaarhoven, but the issue has been fixed and will be released with the version 10.0.0 of the SDK, you can try it out now in the latest beta 10.0.0-theming-v2.3 and let us know, closing for now.

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