Describe the bug#
In a .svelte component, exhaustive-deps fails to flag missing variables in a queryKey.
<script>
import { createQuery } from '@tanstack/svelte-query';
let id = $state(1);
const todo = createQuery(() => ({
queryKey: ['todo'],
queryFn: () => fetchTodo(id),
}));
</script>
However, if you put createQuery inside a function, suddenly it works again.
function createTodo(id) {
return createQuery(() => ({
queryKey: ['todo'],
queryFn: () => fetchTodo(id),
}));
}
I think this is because the rule currently treats the enclosing function as the component (a la React). In the Svelte adapter, that function is always the createQuery accessor, which declares nothing in the function body, so every $props/$state/$derived in the actual top level gets ignored.
Your minimal, reproducible example#
https://stackblitz.com/edit/stackblitz-starters-jiae8x7n?file=src%2Froutes%2F%2Bpage.svelte&view=editor
Steps to reproduce#
- Run
npm install.
- Run
npm run lint.
- Observe that the
@tanstack/query/exhaustive-deps rule only fails when createQuery is nested inside a function.
Expected behavior#
The lint rule should've flagged at the top-level createQuery.
How often does this bug happen?#
Every time
Screenshots or Videos#
No response
Platform#
N/A because the issue points to a non-platform-dependent parser/traversal bug.
Tanstack Query adapter#
svelte-query
TanStack Query version#
6.4.1
TypeScript version#
No response
Additional context#
Note that the .vue fallback added in #10011 (for #9962) doesn't apply to .svelte files. Some logic can be shared/adapted, though! That would be great place to start.