Do you have to manually unsubscribe from subscriptions? #2200
-
This might be a silly question but I could not find concrete information on this anywhere. When you open a subscription on component mount, do you have to ever manually unsubscribe using pause, for example on dismount? I am wondering this because I have been having some trouble keeping subscriptions alive in React Native when the app state changes from background to foreground or when it just has been running for a while. I thought it might have something to do with subscriptions being duplicated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
No, like with queries, as soon as your component unmounts the subscription will be terminated/cancelled. So, as long as you use the bindings, this will all be taken care of for you. However, Websockets connections themselves may be a different topic. Depending on how your WebSockets/Subscriptions client is implemented, |
Beta Was this translation helpful? Give feedback.
-
Take note that I'm using SvelteKit with |
Beta Was this translation helpful? Give feedback.
No, like with queries, as soon as your component unmounts the subscription will be terminated/cancelled.
It's important to note that the pattern described in the "Architecture" section of the docs applies to all operations: https://formidable.com/open-source/urql/docs/architecture/#requests-and-operations-on-the-client
(With mutations being the only "special" operation)
So, as long as you use the bindings, this will all be taken care of for you.
However, Websockets connections themselves may be a different topic. Depending on how your WebSockets/Subscriptions client is implemented,
urql
only "forwards" operations to it, as described on the Subscriptions page, so managing the WebSockets/Su…