T
TanStack9mo ago
unwilling-turquoise

Cache Invalidation Issue with Prefetching

With the latest current release of Svelte query and Svelte 5, I'm having an issue with invalidating queries upon a mutation. Take a simple prefetch for example in a +page.ts file,
export const load = async ({ parent, fetch }) => {
const { queryClient } = await parent();
await queryClient.prefetchQuery(queryHandler({ fetch }).users.me());
};
export const load = async ({ parent, fetch }) => {
const { queryClient } = await parent();
await queryClient.prefetchQuery(queryHandler({ fetch }).users.me());
};
If I perform a mutation upon this query, I also have to call InvalidateAll from the sveltekit api. This is pretty much bare bones and setup directly from the docs. Is anyone else having this issue with latest releases?
1 Reply
unwilling-turquoise
unwilling-turquoiseOP9mo ago
const updateMutation = createMutation({
...queryHandler().users.update(),
onSuccess: async () => {
await invalidateAll();
await data.queryClient.invalidateQueries();
}
});
const updateMutation = createMutation({
...queryHandler().users.update(),
onSuccess: async () => {
await invalidateAll();
await data.queryClient.invalidateQueries();
}
});
to explain a bit more, it seems when the query is prefetched in the load function, I have to call invalidateAll() to actually trigger the query to rerun and grab new data

Did you find this page helpful?