fix(svelte): Move Client subscription to writable start #3331
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #3329
Summary
This moves the source subscription to the result
writable
inqueryStore
andsubscriptionStore
. We must subscribe when theStartStopNotifier
is called, so to start the subscription whenever there isn't an active one to theClient
.If we don't start the subscription on demand, then unsubscribing (with all observers) from the stores will let them “die”. They won’t have an active subscription and won’t be able to start a new one.
The
writable
in Svelte already checks when to callStartStopNotifier
via semaphore logic, so no extra code is needed.The only risk with this fix is whether people relied on
queryStore
starting a subscription implicitly. This really shouldn't have been done before as it's pointless to instantiate a store without reading from it, so I don't consider it a breaking change — unless there's a specific reproduction that is proven to break from this change.Set of changes
Client
subscription intowritable
instantiation