-
Notifications
You must be signed in to change notification settings - Fork 462
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
Svelte: using get or subscribing and unsubscribing on queryStore response breaks the store #3329
Comments
Nice catch! 👏 Yes, after the proposed refactor that we got for The reason why this probably didn't occur to me — and why you can also work around this rather easily — is that the So, you could also create multiple This basically should also make the fix quite simple. Since On an unrelated note, you can actually see that urql/packages/vue-urql/src/useQuery.ts Lines 393 to 409 in 45d686e
I could actually imagine that we could integrate this natively into The double subscription is also quite common and must be done in React to determine initial state, ergo, using |
Describe the bug
When using the Svelte query store (possibly other's I'm not using them yet), if you call
get
on the returned store immediately after callingqueryStore
then the store will be broken and no longer propagate results or cache updates. This issue also exhibits itself if you call subscribe and later on unsubscribe before any other subscriptions are made, then the value in the store will be frozen at the time you unsubscribe and no cache updates or results will be propagated.I encountered this issue when I attempt to await the query store with a promise, Something like this:
I just want to await until the store has finished fetching and then clean up my subscription. But I still want to pass the
resultStore
to the caller so they can get cache updates later on.My reproduction on stackblitz is much simpler, I just calling the
queryStore
function, callget
on the store to break it. Then subscribe and assign the value to a variable for use in Svelte. This should work just fine and if you comment out theget
then it does work exactly as expected. However with theget
call the store breaks and never receives the result from the server.Taking a look at the source it looks like the problem is here, we unsubscribe when the store is unsubscribed from by the last observer, however if another observer comes after that we don't subscribe again and the store stays broken. I believe the correct fix would be to execute the pipe call on line 146 inside the
writable
callback on line 142, though care would need to be taken so thatexecuteRequestOperation
is not called more than once.As a workaround for now I'm going to use my first subscription to propagate values to another store that I setup.
Reproduction
https://stackblitz.com/edit/github-pznkt1?file=src%2FPokemonList.svelte
Urql version
urql: 4.10
urql/svelte: 4.0.3
svelte: 4.0.5
Validations
The text was updated successfully, but these errors were encountered: