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
Tanstack Query for Svelte 5 does not rerender when adding a dependency variable #7227
Comments
I have the same issue, I would expect infinite query to refetch page 0 with different parameters (or do anything at all) when part of the array key changes, as a temporary workaround I am using: enabled: false and manually triggering refetch in a reactive statement $postQuery.refetch({ refetchPage: 0 }); |
Please show a minimal reproduction with codesandbox or stackblitz |
To my knowledge, Tanstack Query has yet to support Svelte 5 runes, so directly feeding The Tanstack Query 5 documentation mentions you can pass options as a Alternatives like Svelte 4 reactive statements or re-creating the query in a To make it a bit more ergnomic you can simplify the creation of a reactive store from your runes with a function like: const toReadable = (cb) => readable(cb(), set => $effect.pre(() => set(cb()))); and then do something like: let dependency = $state("something");
const query = createQuery(toReadable(() => ({
queryKey: ["Resource", dependency],
queryFn: () => getSomething(dependency)
}))); However, note that the above example is for let dependencyVariable = writable("whatever");
let query = createInfiniteQuery(
derived(dependencyVariable, ($dependencyVariable) => ({
queryKey: ["Resource", $dependencyVariable],
queryFn: async ({ pageParam }) => {
// Implementation omitted for brevity
},
getNextPageParam(lastPage) {
// Implementation omitted for brevity
},
initialPageParam: null as string | null | undefined,
initialDataUpdatedAt: () => Date.now(),
}))
); However, this gives me a lot of type errors, suggesting it is not the way to do it. An additional example in the documentation specifically demonstrating how to use |
Can you please create a stackblitz reproduction? |
Describe the bug
Issue Description:
Problem:
When utilizing the createInfiniteQuery client to manage infinite queries, there is an issue with updating the query despite the addition of a dependency variable in the query key.
Steps to Reproduce:
Initialize a query using createInfiniteQuery.
Define a queryKey that includes generic variables.
Implement the queryFn function to handle data retrieval based on certain conditions.
Attempt to update the query based on changes in the dependency variable within the queryKey.
Actual Behavior:
Despite adding the dependency variable to the queryKey, the query does not update as expected when the variable changes.
Code Snippet:
javascript
Environment:
Framework/Libraries: SVELTE 5
Possible Solutions:
Review the implementation of createInfiniteQuery to ensure proper handling of dependency variables.
Check for any inconsistencies or errors in the query key setup.
Consider alternative approaches for managing infinite queries that may better accommodate dynamic updates.
Your minimal, reproducible example
I have added an example code below
Steps to reproduce
Steps to Reproduce:
Initialize a query using createInfiniteQuery.
Define a queryKey that includes generic variables.
Implement the queryFn function to handle data retrieval based on certain conditions.
Attempt to update the query based on changes in the dependency variable within the queryKey.
Expected Behavior:
The query should update accordingly when there are changes in the dependency variable included in the queryKey.
Expected behavior
Expected Behavior:
The query should update accordingly when there are changes in the dependency variable included in the queryKey.
How often does this bug happen?
Every time
Screenshots or Videos
test
Platform
Any platform
Tanstack Query adapter
None
TanStack Query version
@tanstack/svelte-query
TypeScript version
5.4.3
Additional context
Additional Context:
This issue impacts the ability to dynamically update queries based on changing dependency variables, hindering the functionality of the application.
The text was updated successfully, but these errors were encountered: