Skip to content
Source
Sign inSign up
TanStack/query

[eslint-plugin-query] `exhaustive-deps` rule ignores top-level `<script>` variables in `.svelte` files #12552

Send to my agent
OpenBastiDood(GitHub profile, opens in a new tab) opened this issue 0 comments

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);

  // `id` is missing from the `queryKey`, yet no errors flagged!
  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

  1. Run npm install.
  2. Run npm run lint.
  3. 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.

  1. tanstack-source added labelsbug

Sign in to join this conversation.