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: MessageList does not respond to stateful customActiveChannel prop after initial render #2656

Open
lukewilson2002 opened this issue Mar 1, 2025 · 2 comments
Labels

Comments

@lukewilson2002
Copy link

lukewilson2002 commented Mar 1, 2025

I am trying to set the user's focused channel from a URL parameter once the page loads, and after the client has initialized. I get this channel URL and try to set the customActiveChannel value but it doesn't seem to update if it's a stateful value that starts undefined.

To Reproduce

Steps to reproduce the behavior:

  1. Create a stateful value: const [activeChannel, setActiveChannel] = useState<string | undefined>(undefined)
  2. Call setActiveChannel after the initial load and once MessageList has already received a prop of customActiveChannel = undefined
  3. After the value has been changed and the component is rendered, the MessageList won't have the channel selected and nothing has changed.

Expected behavior

The ChannelList should focus the channel with the id of customActiveChannel prop if it has changed.

Package version

  • stream-chat-react: 12.10.0
  • stream-chat-css:
  • stream-chat-js: 8.55

Desktop:

  • OS: macOS Silicon
  • Browser Chrome
  • Version 133
@lukewilson2002 lukewilson2002 added bug Something isn't working status: unconfirmed labels Mar 1, 2025
@lukewilson2002 lukewilson2002 changed the title bug: Unable to set MessageList prop customActiveChannel after initial render bug: MessageList does not respond to stateful customActiveChannel prop after initial render Mar 1, 2025
@MartinCupela
Copy link
Contributor

Hey @lukewilson2002 , are you setting active channel with the following?

  const {setActiveChannel} = useChatContext();

@lukewilson2002
Copy link
Author

lukewilson2002 commented Mar 5, 2025

@MartinCupela Yes, I was but that wasn't working for me.

I eventually made it work as described in my Stack Overflow QA: https://stackoverflow.com/questions/79477012/how-to-set-the-default-focused-channel-for-channellist-and-channel-component-on/79477013#79477013

It seems that either intentionally, or unintentionally, customActiveChannel only applies on component mount and never responds to state changes.

Using setActiveChannel was very difficult for me because I needed to check whether the channel existed on page load in order to present an error toast to the user. It seemed that the client wouldn't be hydrated with the channels until after a few re-renders of the component. Thus, I didn't know when it would be fully ready to check for the channel.

I possibly could have done an API request instead to check if the channel existed, but I thought that would be a waste since the channel must be loaded for the client to focus it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants