Skip to content

fix(vue-query): allow computed ref as enabled property in queryOptions - #10465

Merged
DamianOsipiuk merged 2 commits into
TanStack:mainfrom
byungsker:fix/vue-query-options-enabled-type
Apr 19, 2026
Merged

fix(vue-query): allow computed ref as enabled property in queryOptions#10465
DamianOsipiuk merged 2 commits into
TanStack:mainfrom
byungsker:fix/vue-query-options-enabled-type

Conversation

@byungsker

@byungskerbyungsker commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

🎯 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:

  • boolean values
  • Ref<boolean>
  • ComputedRef<boolean>
  • () => boolean getter functions
  • (query) => boolean query 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 enabled query 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.

FixesTanStack#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.
This change aligns QueryOptions.enabled type with UseQueryOptions.enabled,
allowing:
- boolean values
- Ref<boolean>
- ComputedRef<boolean>
- () => boolean getter functions
- (query) => boolean query predicates
@coderabbitai

coderabbitaiBot commented Apr 12, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This patch fixes a regression in @tanstack/vue-query where queryOptions rejected non-getter enabled properties. The fix updates the type definition to accept enabled as reactive values (boolean, Ref<boolean>, ComputedRef<boolean>) or getter functions, with supporting type tests verifying each form.

Changes

Cohort / File(s)Summary
Changeset Documentation
.changeset/fix-vue-query-options-enabled.md
Added changeset entry documenting patch fix for @tanstack/vue-query, detailing support for enabled as boolean, Ref<boolean>, ComputedRef<boolean>, or getter/predicate functions.
Type Tests
packages/vue-query/src/__tests__/queryOptions.test-d.ts
Added imports for computed from vue-demi and four new type test cases verifying queryOptions accepts enabled as computed ref, standard ref, plain boolean, and getter function.
Type Definition
packages/vue-query/src/queryOptions.ts
Updated QueryOptions.enabled property type to allow MaybeRefOrGetter<boolean | undefined> in addition to existing getter function form () => Enabled<...>.

Poem

🐰 A boolean hops, a ref does gleam,
No getter needed for the dream!
The options dance in freedom's light,
Reactive paths now flowing right! ✨

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check nameStatusExplanation
Title check✅ PassedThe title clearly and specifically describes the main change: allowing computed refs as the enabled property in queryOptions, which directly addresses the bug fix.
Description check✅ PassedThe description follows the template with a clear summary of changes, links to the issue, explains the regression, lists supported types, and includes completed checklist items.
Linked Issues check✅ PassedThe PR successfully addresses issue #10458 by modifying the QueryOptions type to accept reactive values (boolean, Ref, ComputedRef) alongside getter functions, matching the expected behavior described in the issue.
Out of Scope Changes check✅ PassedAll changes are focused on fixing the QueryOptions.enabled type issue: a changeset entry, type definition updates, and corresponding type tests are directly related to the stated objective.
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud

nx-cloudBot commented Apr 12, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 2d8cbde

CommandStatusDurationResult
nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded1m 42sView ↗
nx run-many --target=build --exclude=examples/*...✅ Succeeded1sView ↗

☁️ Nx Cloud last updated this comment at 2026-04-19 10:37:10 UTC

@pkg-pr-new

pkg-pr-newBot commented Apr 12, 2026

Copy link
Copy Markdown
More templates

@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@10465

commit: 2d8cbde

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable 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 24de260 and f222060.

📒 Files selected for processing (3)
  • .changeset/fix-vue-query-options-enabled.md
  • packages/vue-query/src/__tests__/queryOptions.test-d.ts
  • packages/vue-query/src/queryOptions.ts

Comment on lines +292 to +300
it('should allow getter function as enabled property', () => {
const options = queryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve(1),
enabled: () => true,
})

expectTypeOf(options.queryKey).not.toBeUndefined()
})

@coderabbitaicoderabbitaiBotApr 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bashset -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.ts

Repository: 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.ts

Repository: 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 -5

Repository: 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 -5

Repository: 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.ts

Repository: 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 -30

Repository: 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.ts

Repository: TanStack/query

Length of output: 370


Add a type test for the predicate form enabled: () => (query) => boolean to prevent regression.

The current test coverage includes computed ref, ref, boolean, and a simple getter function returning true. However, the Enabled type 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.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 #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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@byungsker, thanks for testing and clarifying! That's a good point — the predicate form (query) => boolean being unsupported in queryOptions is a pre-existing limitation unrelated to this PR. The existing tests you've added correctly cover the regression cases from #10452 (ComputedRef, Ref, and plain boolean), 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 to queryOptions as 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.

@DamianOsipiuk
DamianOsipiuk merged commit c2d0dff into TanStack:mainApr 19, 2026
8 checks passed
@github-actionsgithub-actionsBot mentioned this pull request Apr 19, 2026
Ephem pushed a commit to Ephem/react-query that referenced this pull request Apr 23, 2026
TanStack#10465)
FixesTanStack#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.
This change aligns QueryOptions.enabled type with UseQueryOptions.enabled,
allowing:
- boolean values
- Ref<boolean>
- ComputedRef<boolean>
- () => boolean getter functions
- (query) => boolean query predicates
Co-authored-by: Damian Osipiuk <osipiukd+git@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[vue-query] queryOptions does not allow non-getter enabled property

2 participants

@byungsker@DamianOsipiuk