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

is this hooks automatically disconnect channels? #40

Open
201524547 opened this issue Jan 29, 2021 · 8 comments
Open

is this hooks automatically disconnect channels? #40

201524547 opened this issue Jan 29, 2021 · 8 comments

Comments

@201524547
Copy link

useChannel hooks automatically disconnect channels?

i use this hooks, i wonder useChannel hook automatically disconnect when component unmount?

@mayteio
Copy link
Owner

mayteio commented Jan 29, 2021

Thanks for letting me know. Do you have a codesandbox that reproduces this?

@underfisk
Copy link

underfisk commented Feb 7, 2021

@201524547 It was something i had reported time ago, it disconnects and never re-connects back to the channel if the component re-renders
@mayteio All you have to do is simply have a component that with a parent or some dependency that make it re-render and test having the useChannel with some useEvent and you'll notice the first time pusher invokes your callback its okay but the 2nd time after component gets re-rendered it just unbinds the channel (disconnecting or not) and the callbacks are no longer doing anything

@mayteio
Copy link
Owner

mayteio commented Feb 9, 2021

Please provide a codesandbox - I do not have this issue.

@underfisk
Copy link

Sure i'll do that but i think i found why its probably happening, let me explain it quickly
There are types of channels that need to be persisted while the application is on, usually those are bounded to the user itself and not to the component, useChannel makes it unsubscribe on unmount and what if a component uses a user room that needs to be alive while the app is running? That was in fact one of the issues, my workaround was creating a custom useChannel that just simply doesn't unsubscribe but removes the event only but i think there is room for improvement.
Do you think that considering a parameter option whether we can unsubscribe or not? It does make sense having it unsubscribing on unmount but sometimes you don't want that channel to go away in sub-components, not sure what's your suggestion in here. Once i have some free time i'll publish here the issue

@mayteio
Copy link
Owner

mayteio commented Feb 9, 2021

Hey, why don’t you move the useChannel hook higher up into a provider? That way it can live connected for the duration of the session.

@underfisk
Copy link

At some point if my event uses that channel somehow its unsubscribing, i tried that but i can check again
What i ended up doing is check if the channel exists and re-use but never close it (only the higher up provider) is closing it
but probably i might be doing something wrong

@mayteio
Copy link
Owner

mayteio commented Feb 25, 2021

Might #43 solve this too?

@jan-wilhelm
Copy link

yeah, I ran into the same problem and (as far as I can tell), #43 would solve this perfectly.

mayteio added a commit that referenced this issue Aug 11, 2022
Some improvements...

#89 Incompatible with React versions >16
#40 is this hooks automatically disconnect channels?
#43 Introduce to hoist channel connection
#44 useChannel(false) to prevent eager channel connection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants