Should you ever use RealtimeClient.channel.unsubscribe()?
I had been "cleaning up" my realtime subscriptions by calling unsubscribe(), but it looks to me like that's not the intended flow? I thought if I called unsubscribe() on the channel object, I could call subscribe() later to resubscribe, but that fails since unsubscribe() doesn't set this.joinedOnce = false
There's also removeChannel(), which seems like it must be the intended way to do this? I wasn't using it because it has the side effect of closing the websocket if the number of channels reaches zero which I was finding annoying in React Strict mode (my app always needs the socket open), but if that's the correct way to clean up realtime subscriptions then I'd rather deal with fixing those issues. I just wanted to understand the intent of channel.unsubscribe() when RealtimeClient.removeChannel seems like the only "correct" way to do this!
1 Reply
i only see remove channel in the docs myself, it may be deprecated or not recommended as much these days similar to using 'postgres_changes' vs 'broadcast'. They are both in use still but the latter is reccomended more