Skip to content

fix(eslint-plugin-query): handle array-destructured useQueries result…#1

Merged
vinamra1102 merged 1 commit into
mainfrom
fix/no-unstable-deps-array-pattern
May 21, 2026
Merged

fix(eslint-plugin-query): handle array-destructured useQueries result…#1
vinamra1102 merged 1 commit into
mainfrom
fix/no-unstable-deps-array-pattern

Conversation

@vinamra1102

Copy link
Copy Markdown
Owner

What does this PR fix?

The no-unstable-deps rule silently ignores array-destructured results
from useQueries and useSuspenseQueries. Writing:

const [userQuery, postsQuery] = useQueries({ queries: [...] })

causes neither variable to be tracked as unstable, so using them in
useEffect dependency arrays is never flagged — even though it should be.

Root cause

collectVariableNames in no-unstable-deps.rule.ts only handled
Identifier patterns. When the result is array-destructured, the id
node is an ArrayPattern which was silently ignored.

Evidence this is unintentional

The sibling rule no-rest-destructuring already handles ArrayPattern
correctly for useQueries and useSuspenseQueries (lines 69–86 of
no-rest-destructuring.rule.ts), confirming this pattern is expected
and no-unstable-deps had a gap.

Fix

Added ArrayPattern handling to collectVariableNames to iterate over
elements and track each destructured variable individually, including
rest elements.

Tests added

  • Invalid: useQueries array element used as dep → flagged
  • Invalid: useSuspenseQueries array element used as dep → flagged
  • Invalid: rest element (...restQueries) used as dep → flagged

Related issue

Fixes TanStack#10746

…s in no-unstable-deps

The `collectVariableNames` function in the `no-unstable-deps` rule only
handled `Identifier` patterns. When users array-destructure `useQueries`
or `useSuspenseQueries` results (e.g. `const [q1, q2] = useQueries(...)`),
the individual variables were not tracked as unstable. This meant passing
them directly to React hook dependency arrays was never flagged.

Extend `collectVariableNames` to also handle `ArrayPattern` — including
plain identifier elements and rest elements.

Fixes TanStack#10746
@vinamra1102 vinamra1102 merged commit 6ce381a into main May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] no-unstable-deps rule misses array-destructured useQueries results

1 participant