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

bug: Channel list component never updates custom handler for onMessageNewHandler #2524

Closed
hkasabas opened this issue Sep 25, 2024 · 2 comments · Fixed by #2525
Closed

bug: Channel list component never updates custom handler for onMessageNewHandler #2524

hkasabas opened this issue Sep 25, 2024 · 2 comments · Fixed by #2525
Labels
bug Something isn't working released on @latest status:confirmed Described issue has been reproduced by the repo maintainer

Comments

@hkasabas
Copy link

Describe the bug

We're using component ChannelList and passing some custom event handlers (eg. onMessageNewHandler). That component uses hook useMessageNewListener to subscribe to message.new event and run some internal logic or to run custom event handler. Internally, hook uses useEffect to manage event subscription but since customHandler prop is not in effect's dependecies, it never updates it so we're always stuck with the inital event callback version which then contains stale component state.

To Reproduce

Steps to reproduce the behavior:

  1. Create a React component
  2. Make a custom callback event function that depends on some local state that changes over time and log that state in console
  3. Use ChannelList component and pass it that event handler in onMessageNewHandler property
  4. Console log that state from component
  5. Trigger message.new event
  6. See that event handler logs the first state value and not the latest one

Expected behavior

When an event handler for ChannelList.onMessageNewHandler changes (eg. because useCallback() dependecies chaged), component should update and use the latest handler version on next appropriate event.

Package version

  • stream-chat-react: 11.23.10, 12.0.0

Desktop (please complete the following information):

  • OS: Ubuntu
  • Browser: Chrome
  • Version: 129.0.6668.58

Additional context

v12.0.0 - https://github.com/GetStream/stream-chat-react/blob/master/src/components/ChannelList/hooks/useMessageNewListener.ts#L51

v11.23.10 - https://github.com/GetStream/stream-chat-react/blob/v11.23.10/src/components/ChannelList/hooks/useMessageNewListener.ts#L51

@hkasabas hkasabas added bug Something isn't working status: unconfirmed labels Sep 25, 2024
@MartinCupela MartinCupela added status:confirmed Described issue has been reproduced by the repo maintainer and removed status: unconfirmed labels Sep 26, 2024
@MartinCupela
Copy link
Contributor

@hkasabas thank you for bringing this up.

@stream-ci-bot
Copy link

🎉 This issue has been resolved in version 12.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released on @latest status:confirmed Described issue has been reproduced by the repo maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants