fix(vue-query): unwrap getter options in fetchQuery #11103
main fromrefs/pull/11103/head·opened View on GitHubFixes #11102
🎯 Changes#
QueryClient.fetchQuery has an overload that accepts a getter function returning FetchQueryOptions, but the runtime path passed that top-level function directly to query-core.
This PR evaluates top-level getter options before applying the existing deep-unref behavior.
Changes included:
- Add a small helper to unwrap top-level getter options before
cloneDeepUnref - Use it in
queryClient.fetchQuery - Add regression coverage for
fetchQuery(() => options) - Add a patch changeset for
@tanstack/vue-query
✅ 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).
Tests#
pnpm run test:prpnpm nx run @tanstack/vue-query:test:lib -- queryClient.test.tspnpm nx run @tanstack/vue-query:test:typespnpm nx run @tanstack/vue-query:test:eslintpnpm exec prettier --check .changeset/vue-query-fetch-query-getter-options.md packages/vue-query/src/queryClient.ts packages/vue-query/src/__tests__/queryClient.test.ts
Summary by CodeRabbit#
New Features
fetchQuerynow accepts getter functions that return query options.- Getter-based options are evaluated and reactive values are automatically unwrapped before fetching data.
Bug Fixes
- Improved compatibility when using reactive or computed query options with
fetchQuery.
- Improved compatibility when using reactive or computed query options with
Documentation
- Added a patch release note for the Vue Query package.
- 1
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. Inline comments: In `@packages/vue-query/src/queryClient.ts`: - Around line 36-41: Update the fetchQuery overload’s getter branch to accept () => MaybeRefDeep<FetchQueryOptions<...>> instead of only () => FetchQueryOptions<...>, matching cloneDeepUnrefOrGet runtime support for ref-bearing options while preserving the existing non-getter overload behavior.🪄 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:
74cf3a52-8bdf-4c55-9ef2-fac18a9d7107📥 Commits
Reviewing files that changed from the base of the PR and between 86bb8a6fb2c7f15c74ff50afba053d778e6edc23 and 3d7340986a9950cdc1db42a43c080fd19241271a.
📒 Files selected for processing (3)
.changeset/vue-query-fetch-query-getter-options.mdpackages/vue-query/src/__tests__/queryClient.test.tspackages/vue-query/src/queryClient.ts
packages/vue-query/src/queryClient.ts lines 37 to 42Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -33,3 +33,9 @@3333 Updater,3434 } from '@tanstack/query-core'353536+type MaybeRefDeepOrGetter<T> = MaybeRefDeep<T> | (() => T)37+38+function cloneDeepUnrefOrGet<T>(value: MaybeRefDeepOrGetter<T>): T {39+ const unwrapped = typeof value === 'function' ? (value as () => T)() : value40+41+ return cloneDeepUnref(unwrapped as MaybeRefDeep<T>)🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash set -euo pipefail # Map relevant files and locate the types/overloads/test cases. git ls-files packages/vue-query/src/queryClient.ts packages/vue-query/src | sed -n '1,120p' printf '\n--- outline queryClient.ts ---\n' ast-grep outline packages/vue-query/src/queryClient.ts --view expanded || true printf '\n--- search for MaybeRefDeepOrGetter and getter overloads ---\n' rg -n "MaybeRefDeepOrGetter|cloneDeepUnrefOrGet|FetchQueryOptions|MaybeRefDeep<FetchQueryOptions|\\(\\) =>" packages/vue-query/src packages/vue-query/test -S || true printf '\n--- find query getter-related tests ---\n' rg -n "queryKeyRef|getter|deep ref|MaybeRefDeep" packages/vue-query -S || trueRepository: TanStack/query
Length of output: 50371
🏁 Script executed:
#!/bin/bash set -euo pipefail # Read the relevant portion of queryClient.ts with line numbers. sed -n '1,180p' packages/vue-query/src/queryClient.ts | cat -nRepository: TanStack/query
Length of output: 6963
🏁 Script executed:
#!/bin/bash set -euo pipefail # Inspect package typings and tests around the Vue Query client helpers. find packages/vue-query -maxdepth 3 -type f | sort | sed -n '1,200p'Repository: TanStack/query
Length of output: 3128
🏁 Script executed:
#!/bin/bash set -euo pipefail sed -n '1,220p' packages/vue-query/src/queryClient.ts | cat -nRepository: TanStack/query
Length of output: 8707
🌐 Web query:
packages/vue-query/src/queryClient.ts MaybeRefDeepOrGetter FetchQueryOptions vue query getter deep refs💡 Result:
In TanStack Vue Query,
MaybeRefDeepOrGetteris a type utility introduced to support bothMaybeRef(Vue refs) and getter functions (() => T) within query options [1]. This allows for more flexible, reactive configurations that can handle complex, nested structures [1]. ### Core Concepts MaybeRefDeep: Recursively transforms properties of typeTintoMaybeRef<T>, allowing deep reactivity where individual properties of an options object can be Vue refs [2]. MaybeRefOrGetter: A union type (MaybeRef<T> | (() => T)) that allows passing either a static value, a Vue ref, or a getter function [2]. * MaybeRefDeepOrGetter: Extends the concept to handle deeply reactive objects while also permitting the entire object (or specific parts of it) to be returned by a getter function [1]. ### Technical Context in queryClient.ts Inpackages/vue-query/src/queryClient.ts, methods likefetchQueryandprefetchQueryutilize these type utilities to normalize incoming options [3][4]. Specifically, these methods applycloneDeepUnrefto the options object before passing them to the underlyingquery-coreimplementation [3][4].cloneDeepUnrefis a utility defined inpackages/vue-query/src/utils.tsthat performs several key tasks [5]: 1. Deep Unwrapping: It recursively traverses the options object to unwrapRefvalues [5]. 2. Getter Resolution: It can be configured (by settingunrefGettersto true) to execute getter functions, allowing it to resolve reactive dependencies even when they are wrapped in functions rather than just refs [5]. 3. Integration: This mechanism bridges the gap between Vue's reactive system and the imperative, static-options-based nature of the core TanStack Query library [3][5]. ### Recent Developments Recent PRs and issues indicate ongoing refinements to these type utilities to ensure that getters and plain properties are handled correctly across all query methods, such asensureQueryDataandfetchQuery[6][7]. The goal of these changes is to maintain strict TypeScript compatibility while providing a seamless developer experience that mirrors howuseQueryhandles reactive options [6][1].Citations:
- 1: https://github.com/TanStack/query/pull/10036
- 2: https://github.com/TanStack/query/blob/main/packages/vue-query/src/types.ts
- 3: https://github.com/TanStack/query/blob/d4fd9417/packages/vue-query/src/queryClient.ts
- 4: https://github.com/TanStack/query/blob/d6884583/packages/vue-query/src/queryClient.ts
- 5: https://github.com/TanStack/query/blob/feb1efd8/packages/vue-query/src/utils.ts
- 6: https://github.com/TanStack/query/pull/10452
- 7: https://github.com/TanStack/query/issues/6477
🏁 Script executed:
#!/bin/bash set -euo pipefail # Inspect the exact helper and overload area in the source file. nl -ba packages/vue-query/src/queryClient.ts | sed -n '30,70p;290,320p'Repository: TanStack/query
Length of output: 192
🏁 Script executed:
#!/bin/bash set -euo pipefail # Inspect the fetchQuery/prefetchQuery typings and the relevant d.ts tests. sed -n '260,360p' packages/vue-query/src/queryClient.ts | cat -n printf '\n--- queryClient.test-d.ts ---\n' sed -n '1,220p' packages/vue-query/src/__tests__/queryClient.test-d.ts | cat -nRepository: TanStack/query
Length of output: 9424
Allow deep refs in
fetchQuerygetters.cloneDeepUnrefOrGet()unwraps getter results, but thefetchQueryoverload still types the getter branch as() => FetchQueryOptions<...>. That rejects getters returning ref-bearing options even though runtime accepts them. Change it to() => MaybeRefDeep<FetchQueryOptions<...>>so the type surface matches behavior.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/vue-query/src/queryClient.ts` around lines 36 - 41, Update the fetchQuery overload’s getter branch to accept () => MaybeRefDeep<FetchQueryOptions<...>> instead of only () => FetchQueryOptions<...>, matching cloneDeepUnrefOrGet runtime support for ref-bearing options while preserving the existing non-getter overload behavior.✅ Addressed in commits 3d73409 to b7cdf5c
Note
GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.
View your CI Pipeline Execution ↗ for commit b7cdf5ca95413090a66d25801b3a8fa932b6cfca
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 5m 31s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 10s View ↗
☁️ Nx Cloud last updated this comment at
2026-08-20 15:25:50UTCMore 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-lit-basic
- @tanstack/query-example-lit-pagination
- @tanstack/query-example-lit-ssr
- @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-react-batching
- @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-optimistic-updates
- @tanstack/query-example-react-nextjs-app-prefetching
- @tanstack/query-example-nextjs-suspense-streaming
- @tanstack/query-example-react-offline
- @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@11103@tanstack/eslint-plugin-query
npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@11103@tanstack/lit-query
npm i https://pkg.pr.new/@tanstack/lit-query@11103@tanstack/preact-query
npm i https://pkg.pr.new/@tanstack/preact-query@11103@tanstack/preact-query-devtools
npm i https://pkg.pr.new/@tanstack/preact-query-devtools@11103@tanstack/preact-query-persist-client
npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@11103@tanstack/query-async-storage-persister
npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@11103@tanstack/query-broadcast-client-experimental
npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@11103@tanstack/query-core
npm i https://pkg.pr.new/@tanstack/query-core@11103@tanstack/query-devtools
npm i https://pkg.pr.new/@tanstack/query-devtools@11103@tanstack/query-persist-client-core
npm i https://pkg.pr.new/@tanstack/query-persist-client-core@11103@tanstack/query-sync-storage-persister
npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@11103@tanstack/react-query
npm i https://pkg.pr.new/@tanstack/react-query@11103@tanstack/react-query-devtools
npm i https://pkg.pr.new/@tanstack/react-query-devtools@11103@tanstack/react-query-next-experimental
npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@11103@tanstack/react-query-persist-client
npm i https://pkg.pr.new/@tanstack/react-query-persist-client@11103@tanstack/solid-query
npm i https://pkg.pr.new/@tanstack/solid-query@11103@tanstack/solid-query-devtools
npm i https://pkg.pr.new/@tanstack/solid-query-devtools@11103@tanstack/solid-query-persist-client
npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@11103@tanstack/svelte-query
npm i https://pkg.pr.new/@tanstack/svelte-query@11103@tanstack/svelte-query-devtools
npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@11103@tanstack/svelte-query-persist-client
npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@11103@tanstack/vue-query
npm i https://pkg.pr.new/@tanstack/vue-query@11103@tanstack/vue-query-devtools
npm i https://pkg.pr.new/@tanstack/vue-query-devtools@11103commit:
b7cdf5cbyungsker(GitHub profile, opens in a new tab) linked this to fix #11102
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID:
27fc20d3-d5d5-429d-8cd4-abf9cff4e77b📥 Commits
Reviewing files that changed from the base of the PR and between 97ce30b51e3040752f3f4172e9fd11be4edea774 and b7cdf5ca95413090a66d25801b3a8fa932b6cfca.
📒 Files selected for processing (3)
.changeset/vue-query-fetch-query-getter-options.mdpackages/vue-query/src/__tests__/queryClient.test.tspackages/vue-query/src/queryClient.ts🚧 Files skipped from review as they are similar to previous changes (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
📝 Walkthrough
Walkthrough#
@tanstack/vue-querynow evaluates getter functions passed tofetchQuery, deep-unrefs the returned options, forwards them to query-core, and adds regression coverage plus a patch Changesets entry.Changes#
Fetch query getter options
packages/vue-query/src/queryClient.tsfetchQueryto evaluate and deep-unref getter-provided options before delegation.packages/vue-query/src/__tests__/queryClient.test.ts,.changeset/vue-query-fetch-query-getter-options.mdEstimated code review effort: 2 (Simple) | ~10 minutes
Merge Risk: ⚪ Minimal · up to
b7cdfThis localized fix evaluates getter-based options before fetching and adds regression coverage; no actionable merge-blocking risk remains after normal checks and review.
Sequence Diagram(s)#
Possibly related PRs
fetchQueryto evaluate getter-function options and deep-unref them before delegation.Suggested labels:
package: vue-querySuggested reviewers:
tkdodo🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
#11102].#11102] and the stated fetchQuery getter-unwrapping objective; no unrelated code changes are present.✨ 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