-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(vue-query): allow computed ref as enabled property in queryOptions #10465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
byungsker
wants to merge
1
commit into
TanStack:main
Choose a base branch
from
byungsker:fix/vue-query-options-enabled-type
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+69
β3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| '@tanstack/vue-query': patch | ||
| --- | ||
|
|
||
| fix(vue-query): allow computed ref and other reactive values as `enabled` property in queryOptions | ||
|
|
||
| This fixes a regression introduced in #10452 where `queryOptions` only accepted getter functions for the `enabled` property, but not `computed` refs or other reactive values. | ||
|
|
||
| Now the `enabled` property in `queryOptions` correctly accepts: | ||
| - `boolean` values | ||
| - `Ref<boolean>` | ||
| - `ComputedRef<boolean>` | ||
| - `() => boolean` getter functions | ||
| - `(query) => boolean` query predicate functions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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:
Repository: TanStack/query
Length of output: 40
π Script executed:
Repository: TanStack/query
Length of output: 635
π Script executed:
Repository: TanStack/query
Length of output: 678
π Script executed:
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.tsRepository: TanStack/query
Length of output: 4162
π Script executed:
Repository: TanStack/query
Length of output: 843
π Script executed:
Repository: 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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) => 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
π§ Learnings used