From d9967913dc5fcedb356eecb1c436efb4551d4f1b Mon Sep 17 00:00:00 2001 From: lihan3238 Date: Tue, 5 May 2026 23:38:01 +0800 Subject: [PATCH] fix(eslint-plugin-query): fix no-unstable-deps false positive for useSuspenseQueries The `no-unstable-deps` rule was previously fixed for `useQueries` with `combine` in PR #9720, but the same false positive persists for `useSuspenseQueries` with `combine`. This extends the fix to also recognize `useSuspenseQueries` with a `combine` property as returning a stable value. Closes #10641 --- .../src/__tests__/no-unstable-deps.test.ts | 18 ++++++++++++++++++ .../no-unstable-deps/no-unstable-deps.rule.ts | 7 ++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/eslint-plugin-query/src/__tests__/no-unstable-deps.test.ts b/packages/eslint-plugin-query/src/__tests__/no-unstable-deps.test.ts index b111fc0ed73..be3419242e5 100644 --- a/packages/eslint-plugin-query/src/__tests__/no-unstable-deps.test.ts +++ b/packages/eslint-plugin-query/src/__tests__/no-unstable-deps.test.ts @@ -63,6 +63,24 @@ const baseTestCases = { } `, }, + { + name: `should pass when useSuspenseQueries with combine is passed to ${reactHookAlias} as dependency`, + code: ` + ${reactHookImport} + import { useSuspenseQueries } from "@tanstack/react-query"; + + function Component() { + const queries = useSuspenseQueries({ + queries: [ + { queryKey: ['test'], queryFn: () => 'test' } + ], + combine: (results) => ({ data: results[0]?.data }) + }); + const callback = ${reactHookInvocation}(() => { queries.data }, [queries]); + return; + } + `, + }, ]) .concat([ { diff --git a/packages/eslint-plugin-query/src/rules/no-unstable-deps/no-unstable-deps.rule.ts b/packages/eslint-plugin-query/src/rules/no-unstable-deps/no-unstable-deps.rule.ts index 32e68464682..25d093f6907 100644 --- a/packages/eslint-plugin-query/src/rules/no-unstable-deps/no-unstable-deps.rule.ts +++ b/packages/eslint-plugin-query/src/rules/no-unstable-deps/no-unstable-deps.rule.ts @@ -112,12 +112,13 @@ export const rule = createRule({ allHookNames.includes(node.init.callee.name) && helpers.isTanstackQueryImport(node.init.callee) ) { - // Special case for useQueries with combine property - it's stable + // Special case for useQueries/useSuspenseQueries with combine property - it's stable if ( - node.init.callee.name === 'useQueries' && + (node.init.callee.name === 'useQueries' || + node.init.callee.name === 'useSuspenseQueries') && hasCombineProperty(node.init) ) { - // Don't track useQueries with combine as unstable + // Don't track useQueries/useSuspenseQueries with combine as unstable return } collectVariableNames(node.id, node.init.callee.name)