Describe the bug
@tanstack/eslint-plugin-query's no-unstable-deps rule performs property lookups on trackedCustomHooks using:
trackedCustomHooks[callExpression.callee.name]
Since trackedCustomHooks is a plain object, inherited Object.prototype properties such as toString, constructor, and valueOf are returned instead of undefined.
As a result, unrelated functions with these names can be treated as tracked TanStack Query hooks, causing false positives from no-unstable-deps.
Your minimal, reproducible example
https://stackblitz.com/edit/vitejs-vite-mwhrnhuz?file=src%2FApp.tsx
Steps to reproduce
- Enable the
@tanstack/query/no-unstable-deps rule.
- Import a function whose name matches an inherited
Object.prototype property, for example toString from Lodash.
- Use it to derive a value and include that value in a React hook dependency array.
import { toString } from 'lodash'
const sessionId = toString(router.query.sessionId)
useCallback(() => {
console.log(sessionId)
}, [sessionId])
- Run ESLint.
Expected behaviour
The rule should only treat explicitly tracked custom hooks as tracked hooks.
Inherited Object.prototype properties should not be considered, so the example above should not produce a no-unstable-deps warning.
Use an own-property check before reading from trackedCustomHooks, for example:
return Object.hasOwn(trackedCustomHooks, calleeName)
? trackedCustomHooks[calleeName]
: undefined
How often does this bug happen?
Everytime
Screenshots or Videos
No response
Platform
ESLint: v10.x
@tanstack/eslint-plugin-query: 5.101.4
Tanstack Query adapter
None
TanStack Query version
5.101.4
TypeScript version
No response
Additional context
I've opened a PR with a proposed fix and regression tests:
PR: #11117
Describe the bug
@tanstack/eslint-plugin-query'sno-unstable-depsrule performs property lookups ontrackedCustomHooksusing:Since
trackedCustomHooksis a plain object, inheritedObject.prototypeproperties such astoString,constructor, andvalueOfare returned instead ofundefined.As a result, unrelated functions with these names can be treated as tracked TanStack Query hooks, causing false positives from
no-unstable-deps.Your minimal, reproducible example
https://stackblitz.com/edit/vitejs-vite-mwhrnhuz?file=src%2FApp.tsx
Steps to reproduce
@tanstack/query/no-unstable-depsrule.Object.prototypeproperty, for exampletoStringfrom Lodash.Expected behaviour
The rule should only treat explicitly tracked custom hooks as tracked hooks.
Inherited
Object.prototypeproperties should not be considered, so the example above should not produce ano-unstable-depswarning.Use an own-property check before reading from
trackedCustomHooks, for example:How often does this bug happen?
Everytime
Screenshots or Videos
No response
Platform
ESLint: v10.x
@tanstack/eslint-plugin-query: 5.101.4
Tanstack Query adapter
None
TanStack Query version
5.101.4
TypeScript version
No response
Additional context
I've opened a PR with a proposed fix and regression tests:
PR: #11117