Skip to content

fix(vue-query): unwrap getter options in fetchQuery#11103

Open
byungsker wants to merge 1 commit into
TanStack:mainfrom
byungsker:fix/vue-query-client-getter-options
Open

fix(vue-query): unwrap getter options in fetchQuery#11103
byungsker wants to merge 1 commit into
TanStack:mainfrom
byungsker:fix/vue-query-client-getter-options

Conversation

@byungsker

@byungsker byungsker commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #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:pr
  • pnpm nx run @tanstack/vue-query:test:lib -- queryClient.test.ts
  • pnpm nx run @tanstack/vue-query:test:types
  • pnpm nx run @tanstack/vue-query:test:eslint
  • pnpm 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

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

@tanstack/vue-query now evaluates getter functions passed to fetchQuery, deep-unrefs the returned options, forwards them to query-core, and adds coverage plus a patch Changesets entry.

Changes

Fetch query getter options

Layer / File(s) Summary
Resolve and clone getter options
packages/vue-query/src/queryClient.ts
Adds a getter-aware option type and helper, then updates fetchQuery to evaluate and deep-unref getter-provided options before delegation.
Validate and release the behavior
packages/vue-query/src/__tests__/queryClient.test.ts, .changeset/vue-query-fetch-query-getter-options.md
Tests that query-core receives unwrapped options and records a patch release describing the behavior change.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant VueQueryQueryClient
  participant QueryClientOrigin
  Caller->>VueQueryQueryClient: fetchQuery(getter)
  VueQueryQueryClient->>VueQueryQueryClient: evaluate getter and deep-unref options
  VueQueryQueryClient->>QueryClientOrigin: fetchQuery(unwrapped options)
Loading

Possibly related PRs

  • TanStack/query#11056: Both changes verify that query options, including query keys, are unwrapped before client processing.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The code evaluates top-level getters, deep-unrefs returned options, and adds regression coverage as requested by #11102.
Out of Scope Changes check ✅ Passed All changes are directly tied to the fetchQuery getter-unwrapping fix and its release note/test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly summarizes the main change in vue-query fetchQuery getter option unwrapping.
Description check ✅ Passed The description follows the template and includes changes, checklist, release impact, and tests.
✨ 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.

@coderabbitai coderabbitai Bot 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 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 86bb8a6 and 3d73409.

📒 Files selected for processing (3)
  • .changeset/vue-query-fetch-query-getter-options.md
  • packages/vue-query/src/__tests__/queryClient.test.ts
  • packages/vue-query/src/queryClient.ts

Comment on lines +36 to +41
type MaybeRefDeepOrGetter<T> = MaybeRefDeep<T> | (() => T)

function cloneDeepUnrefOrGet<T>(value: MaybeRefDeepOrGetter<T>): T {
const unwrapped = typeof value === 'function' ? (value as () => T)() : value

return cloneDeepUnref(unwrapped as MaybeRefDeep<T>)

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.

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

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

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

Repository: 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, MaybeRefDeepOrGetter is a type utility introduced to support both MaybeRef (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 type T into MaybeRef<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 In packages/vue-query/src/queryClient.ts, methods like fetchQuery and prefetchQuery utilize these type utilities to normalize incoming options [3][4]. Specifically, these methods apply cloneDeepUnref to the options object before passing them to the underlying query-core implementation [3][4]. cloneDeepUnref is a utility defined in packages/vue-query/src/utils.ts that performs several key tasks [5]: 1. Deep Unwrapping: It recursively traverses the options object to unwrap Ref values [5]. 2. Getter Resolution: It can be configured (by setting unrefGetters to 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 as ensureQueryData and fetchQuery [6][7]. The goal of these changes is to maintain strict TypeScript compatibility while providing a seamless developer experience that mirrors how useQuery handles reactive options [6][1].

Citations:


🏁 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 -n

Repository: TanStack/query

Length of output: 9424


Allow deep refs in fetchQuery getters. cloneDeepUnrefOrGet() unwraps getter results, but the fetchQuery overload 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[vue-query] queryClient.fetchQuery passes getter options through without unwrapping

1 participant