Closed skokenes closed 1 year ago
Hi @skokenes , I think I've figured out the problem. The current logic to determine whether a store has been passed in checks specifically for properties of writable stores (subscribe, set, update). These aren't all present on derived stores where the return type is the same as readable stores. Therefore, createBaseQuery tries to make a writable store out of the derived store, causing something to break. Derived stores should definitely be supported, so I'll implement a fix shortly.
Relevant files: utils.ts, createBaseQuery.ts
Fixed in #5672 !
Describe the bug
In the documentation for svelte-query v5, it is suggested that you can provide stores for queryOptions in order to make reactive queries: https://tanstack.com/query/v5/docs/svelte/reactivity
This works great with writable stores, as seen in this simple example: https://svelte.dev/repl/7d299dce4d9a4b6ba590d6707f383d62?version=4.0.2
However, it does not work with a derived store, as seen in this example: https://svelte.dev/repl/ee90c13684af4672a19661e9e9021da3?version=4.0.2
The derived store options appear to be completely ignored; no fetching happens.
Your minimal, reproducible example
https://svelte.dev/repl/ee90c13684af4672a19661e9e9021da3?version=4.0.2
Steps to reproduce
Try changing the input box to a different number. Observe that the query never fetches. Also observe in the console that the updated options store value is produced as expected.
Expected behavior
A user should be able to provide a derived store as query options and it should work the same as if a writable store is provided: the query should react to the latest value of the store for its options.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
OSX Chrome
Tanstack Query adapter
svelte-query
TanStack Query version
v5.0.0-alpha.7
TypeScript version
No response
Additional context
No response