-
Notifications
You must be signed in to change notification settings - Fork 56
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
Detach channel in ChannelProvider
#1795
Comments
Is there a shorter term mitigation for this? We switch our channels somewhat regularly and without this our channels are never detached and have hit the 200 channel limit even though most are unused/unsubscribed (and are also billed for the channels) |
It depends on what you want to achieve. Based on your business logic, you can invoke the const DetachableChannelProvider = (channelProviderProps) => {
const ablyClient = useAbly();
const { channelName } = channelProviderProps;
useEffect(() => {
// it's better to explicitly attach to the channel in this case
ablyClient.channels.get(channelName).attach();
return () => ablyClient.channels.get(channelName).detach();
}, [channelName])
return <ChannelProvider {...channelProviderProps} />;
} |
Thanks! I've tried to add this but occasionally get an error when switching channels quickly that I can't seem to resolve. The error is
which seems to be caused by attempting to re-subscribe to a channel that is detaching/detached. Is there anything I can do to handle this? It seems like the |
Hey @ianb-pomelo, I apologize for the delay. I missed the notification about your message. Could you please attach verbose logs or share a reproducible example? I’m having difficulty reproducing the issue you’re facing. |
We should detach channel if there is no
ChannelProvider
associated with it.The reason for doing this is that the SDK user should be able to detach from the channel to stop receiving messages from it. In react-hooks, we fully control the channel lifecycle. Automatic detachment seems more reasonable and better than manual detachment using the Ably client. The best place to do this is inside
ChannelProvider
because this component indicates the intent to use the channel. If it no longer exists, it means we no longer need this channel attached.┆Issue is synchronized with this Jira Task by Unito
The text was updated successfully, but these errors were encountered: