fix(vue-query): allow computed ref as enabled property in queryOptions #10465
main fromrefs/pull/10465/head·merged by DamianOsipiuk(GitHub profile, opens in a new tab) View on GitHub🎯 Changes#
Fixes #10458
The enabled property in QueryOptions type was incorrectly restricted to only accept getter functions (() => Enabled). This prevented using computed refs and other Vue reactive values, which is a regression from #10452.
This change aligns QueryOptions.enabled type with UseQueryOptions.enabled, allowing:
booleanvaluesRef<boolean>ComputedRef<boolean>() => booleangetter functions(query) => booleanquery predicates
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested this code locally with
pnpm run test:pr.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Summary by CodeRabbit#
- Bug Fixes
- Fixed a regression in the
enabledquery option for Vue Query. It now correctly accepts direct reactive boolean values, computed properties, and plain boolean literals alongside existing function-based controls. This improvement allows developers to use simpler, more natural patterns for controlling query execution state without unnecessary function wrappers.
- Fixed a regression in the
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: vue-query
View your CI Pipeline Execution ↗ for commit 2d8cbdebcd413699761e7740739611f21c61dc26
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 1m 42s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 1s View ↗
☁️ Nx Cloud last updated this comment at
2026-04-19 10:37:10UTCMore templates
- @tanstack/query-example-angular-auto-refetching
- @tanstack/query-example-angular-basic
- @tanstack/query-example-angular-basic-persister
- @tanstack/query-example-angular-devtools-panel
- @tanstack/query-example-angular-infinite-query-with-max-pages
- @tanstack/query-example-angular-optimistic-updates
- @tanstack/query-example-angular-pagination
- @tanstack/query-example-angular-query-options-from-a-service
- @tanstack/query-example-angular-router
- @tanstack/query-example-angular-rxjs
- @tanstack/query-example-angular-simple
- @tanstack/query-example-preact-simple
- @tanstack/query-example-react-algolia
- @tanstack/query-example-react-auto-refetching
- @tanstack/query-example-react-basic
- @tanstack/query-example-react-basic-graphql-request
- @tanstack/query-example-chat
- @tanstack/query-example-react-default-query-function
- @tanstack/query-example-react-devtools-panel
- @tanstack/query-example-eslint-legacy
- @tanstack/query-example-eslint-plugin-demo
- @tanstack/query-example-react-infinite-query-with-max-pages
- @tanstack/query-example-react-load-more-infinite-scroll
- @tanstack/query-example-react-nextjs
- @tanstack/query-example-react-nextjs-app-prefetching
- @tanstack/query-example-nextjs-suspense-streaming
- @tanstack/query-example-react-offline
- @tanstack/query-example-react-optimistic-updates-cache
- @tanstack/query-example-react-optimistic-updates-ui
- @tanstack/query-example-react-pagination
- @tanstack/query-example-react-playground
- @tanstack/query-example-react-prefetching
- @tanstack/query-example-react-react-native
- @tanstack/query-example-react-router
- @tanstack/query-example-react-rick-morty
- @tanstack/query-example-react-shadow-dom
- @tanstack/query-example-react-simple
- @tanstack/query-example-react-star-wars
- @tanstack/query-example-react-suspense
- @tanstack/query-example-solid-astro
- @tanstack/query-example-solid-basic
- @tanstack/query-example-solid-basic-graphql-request
- @tanstack/query-example-solid-default-query-function
- @tanstack/query-example-solid-offline
- @tanstack/query-example-solid-simple
- @tanstack/query-example-solid-start-streaming
- @tanstack/query-example-svelte-auto-refetching
- @tanstack/query-example-svelte-basic
- @tanstack/query-example-svelte-load-more-infinite-scroll
- @tanstack/query-example-svelte-optimistic-updates
- @tanstack/query-example-svelte-playground
- @tanstack/query-example-svelte-simple
- @tanstack/query-example-svelte-ssr
- @tanstack/query-example-svelte-star-wars
- @tanstack/query-example-vue-2.6-basic
- @tanstack/query-example-vue-2.7-basic
- @tanstack/query-example-vue-basic
- @tanstack/query-example-vue-dependent-queries
- @tanstack/query-example-vue-nuxt3
- @tanstack/query-example-vue-persister
- @tanstack/query-example-vue-simple
@tanstack/angular-query-experimental
npm i https://pkg.pr.new/@tanstack/angular-query-experimental@10465@tanstack/eslint-plugin-query
npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@10465@tanstack/preact-query
npm i https://pkg.pr.new/@tanstack/preact-query@10465@tanstack/preact-query-devtools
npm i https://pkg.pr.new/@tanstack/preact-query-devtools@10465@tanstack/preact-query-persist-client
npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@10465@tanstack/query-async-storage-persister
npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@10465@tanstack/query-broadcast-client-experimental
npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@10465@tanstack/query-core
npm i https://pkg.pr.new/@tanstack/query-core@10465@tanstack/query-devtools
npm i https://pkg.pr.new/@tanstack/query-devtools@10465@tanstack/query-persist-client-core
npm i https://pkg.pr.new/@tanstack/query-persist-client-core@10465@tanstack/query-sync-storage-persister
npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@10465@tanstack/react-query
npm i https://pkg.pr.new/@tanstack/react-query@10465@tanstack/react-query-devtools
npm i https://pkg.pr.new/@tanstack/react-query-devtools@10465@tanstack/react-query-next-experimental
npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@10465@tanstack/react-query-persist-client
npm i https://pkg.pr.new/@tanstack/react-query-persist-client@10465@tanstack/solid-query
npm i https://pkg.pr.new/@tanstack/solid-query@10465@tanstack/solid-query-devtools
npm i https://pkg.pr.new/@tanstack/solid-query-devtools@10465@tanstack/solid-query-persist-client
npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@10465@tanstack/svelte-query
npm i https://pkg.pr.new/@tanstack/svelte-query@10465@tanstack/svelte-query-devtools
npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@10465@tanstack/svelte-query-persist-client
npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@10465@tanstack/vue-query
npm i https://pkg.pr.new/@tanstack/vue-query@10465@tanstack/vue-query-devtools
npm i https://pkg.pr.new/@tanstack/vue-query-devtools@10465commit:
2d8cbdeActionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed. Inline comments: In `@packages/vue-query/src/__tests__/queryOptions.test-d.ts`: - Around line 292-300: Add a new type test that verifies the predicate getter form for the enabled option: when calling queryOptions with enabled: () => (query) => boolean the resulting options still have the correct types. Specifically, update the test suite around the queryOptions usage (the existing test that uses enabled: () => true) to add another it block that uses enabled: () => (q) => typeof q !== 'undefined' or a simple (q) => true predicate and assert expectTypeOf(options.queryKey).not.toBeUndefined(); reference the queryOptions call and the enabled getter/predicate shape to ensure the Enabled type accepting (query) => boolean is covered.🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
12a9535e-07f6-4b37-824a-c5009c81eb9d📥 Commits
Reviewing files that changed from the base of the PR and between 24de260ad26626a6d5420587f97714f6b94ffa2a and f2220601f8de21a3438bf808bb7f0a1eb80ebf96.
📒 Files selected for processing (3)
.changeset/fix-vue-query-options-enabled.mdpackages/vue-query/src/__tests__/queryOptions.test-d.tspackages/vue-query/src/queryOptions.ts
@@ -255,0 +280,21 @@280+ })281+282+ it('should allow boolean as enabled property', () => {283+ const options = queryOptions({284+ queryKey: ['key'],285+ queryFn: () => Promise.resolve(1),286+ enabled: true,287+ })288+289+ expectTypeOf(options.queryKey).not.toBeUndefined()290+ })291+292+ it('should allow getter function as enabled property', () => {293+ const options = queryOptions({294+ queryKey: ['key'],295+ queryFn: () => Promise.resolve(1),296+ enabled: () => true,297+ })298+299+ expectTypeOf(options.queryKey).not.toBeUndefined()300+ })🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash set -euo pipefail # Verify whether predicate-form coverage already exists in this type test file. rg -n -C2 "enabled:\s*\(\s*query\s*\)\s*=>\s*" packages/vue-query/src/__tests__/queryOptions.test-d.ts # Show current enabled-form test coverage for comparison. rg -n -C2 "enabled:\s*" packages/vue-query/src/__tests__/queryOptions.test-d.tsRepository: TanStack/query
Length of output: 40
🏁 Script executed:
# First, check if the file exists and how many lines it has wc -l packages/vue-query/src/__tests__/queryOptions.test-d.ts # Read lines around 292-300 to see the actual code sed -n '280,310p' packages/vue-query/src/__tests__/queryOptions.test-d.tsRepository: TanStack/query
Length of output: 635
🏁 Script executed:
# Search for all 'enabled' property patterns in the test file rg -n "enabled" packages/vue-query/src/__tests__/queryOptions.test-d.ts # Also check what the queryOptions type signature accepts for enabled parameter fd -t f queryOptions packages/vue-query/src --type typescript --type tsx | head -5Repository: TanStack/query
Length of output: 678
🏁 Script executed:
# Find the queryOptions implementation in vue-query fd -t f queryOptions.ts packages/vue-query/src --exclude "__tests__" # Also check the useQuery type definition to understand enabled parameter fd -t f "useQuery" packages/vue-query/src -e ts -e tsx | grep -v test | head -5Repository: TanStack/query
Length of output: 223
🏁 Script executed:
# Check the queryOptions.ts file to understand the enabled parameter type definition cat -n packages/vue-query/src/queryOptions.tsRepository: TanStack/query
Length of output: 4162
🏁 Script executed:
# Check what the Enabled type is in query-core rg -n "type Enabled" packages/query-core/src # Also check the QueryObserverOptions to understand enabled parameter fully rg -n -A 5 "enabled" packages/query-core/src/types.ts | head -30Repository: TanStack/query
Length of output: 843
🏁 Script executed:
# Get the full definition of the Enabled type rg -n -A 10 "^export type Enabled<" packages/query-core/src/types.tsRepository: TanStack/query
Length of output: 370
Add a type test for the predicate form
enabled: () => (query) => booleanto prevent regression.The current test coverage includes computed ref, ref, boolean, and a simple getter function returning
true. However, theEnabledtype also accepts a predicate function that receives the query object:(query) => boolean. Add a dedicated test case that validates this form through the getter—for example,enabled: () => (query) => boolean—to ensure full type coverage.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/vue-query/src/__tests__/queryOptions.test-d.ts` around lines 292 - 300, Add a new type test that verifies the predicate getter form for the enabled option: when calling queryOptions with enabled: () => (query) => boolean the resulting options still have the correct types. Specifically, update the test suite around the queryOptions usage (the existing test that uses enabled: () => true) to add another it block that uses enabled: () => (q) => typeof q !== 'undefined' or a simple (q) => true predicate and assert expectTypeOf(options.queryKey).not.toBeUndefined(); reference the queryOptions call and the enabled getter/predicate shape to ensure the Enabled type accepting (query) => boolean is covered.Thanks for the review!
Regarding the query predicate test suggestion: I tested it and found that the query predicate form (query) => boolean actually doesn't work with queryOptions - it throws a type error even on the current main branch. This seems to be a pre-existing limitation, not something introduced or changed by this PR.
This PR's scope is specifically fixing the regression from https://github.com/TanStack/query/pull/10452 where ComputedRef, Ref, and plain boolean values stopped working. The added tests cover these cases.
If predicate support in queryOptions is desired, that would be a separate feature request/issue.
@byungsker, thanks for testing and clarifying! That's a good point — the predicate form(query) => booleanbeing unsupported inqueryOptionsis a pre-existing limitation unrelated to this PR. The existing tests you've added correctly cover the regression cases from#10452(ComputedRef,Ref, and plainboolean), and the scope of this PR is appropriate.Would you like me to open a follow-up GitHub issue to track adding predicate (
(query) => boolean) support toqueryOptionsas a separate feature request?
✏️ Learnings added
Learnt from: byungsker Repo: TanStack/query PR: 10465 File: packages/vue-query/src/__tests__/queryOptions.test-d.ts:292-300 Timestamp: 2026-04-13T15:15:48.626Z Learning: In `packages/vue-query/src/queryOptions.ts`, the predicate form of `enabled` — i.e., `(query) => boolean` — is not supported by `queryOptions` (throws a TypeScript error). This is a pre-existing limitation that exists even on the main branch, unrelated to any specific PR. It is distinct from the simple getter form `() => boolean` which is supported. Predicate support in `queryOptions` would require a separate feature implementation.Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
🧠 Learnings used
Learnt from: sukvvon Repo: TanStack/query PR: 9892 File: packages/solid-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx:331-335 Timestamp: 2025-11-22T09:06:05.219Z Learning: In TanStack/query test files, when a queryFn contains side effects (e.g., setting flags for test verification), prefer async/await syntax for clarity; when there are no side effects, prefer the .then() pattern for conciseness.
Learnt from: oscartbeaumont Repo: TanStack/query PR: 9564 File: packages/solid-query-devtools/src/production.tsx:2-3 Timestamp: 2025-08-19T03:18:18.303Z Learning: In the solid-query-devtools package, the codebase uses a pattern of type-only default imports combined with typeof for component type annotations (e.g., `import type SolidQueryDevtoolsComp from './devtools'` followed by `typeof SolidQueryDevtoolsComp`). This pattern is consistently used across index.tsx and production.tsx files, and the maintainers prefer consistency over changing this approach.
Sign in to join this conversation.
📝 Walkthrough
Walkthrough#
This patch fixes a regression in
@tanstack/vue-querywherequeryOptionsrejected non-getterenabledproperties. The fix updates the type definition to acceptenabledas reactive values (boolean,Ref<boolean>,ComputedRef<boolean>) or getter functions, with supporting type tests verifying each form.Changes#
.changeset/fix-vue-query-options-enabled.md@tanstack/vue-query, detailing support forenabledasboolean,Ref<boolean>,ComputedRef<boolean>, or getter/predicate functions.packages/vue-query/src/__tests__/queryOptions.test-d.tscomputedfromvue-demiand four new type test cases verifyingqueryOptionsacceptsenabledas computed ref, standard ref, plain boolean, and getter function.packages/vue-query/src/queryOptions.tsQueryOptions.enabledproperty type to allowMaybeRefOrGetter<boolean | undefined>in addition to existing getter function form() => Enabled<...>.Poem#
Estimated code review effort#
🎯 2 (Simple) | ⏱️ ~12 minutes
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
#10458by modifying the QueryOptions type to accept reactive values (boolean, Ref, ComputedRef) alongside getter functions, matching the expected behavior described in the issue.✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share