Skip to content
Source
Sign inSign up
TanStack/query

fix(vue-query): accept 'UseQueryOptions' in 'query', 'ensureQueryData', 'fetchQuery' and 'prefetchQuery' again #11644

Closedmaximilian-hammerl(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/11644/headopened View on GitHub

🎯 Changes

Fixes #11639. I added the necessary overloads, so that options that useQuery accepts are also accepted by ensureQueryData, fetchQuery and prefetchQuery, as in 5.102.8.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I have followed the AI contribution policy and fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.

Summary by CodeRabbit

  • New Features
    • Vue Query client methods now accept reactive query options, including options with conditional query functions.
    • query, ensureQueryData, fetchQuery, and prefetchQuery retain their expected return types when using these options.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: Repository: TanStack/query/.coderabbit.yaml

      Review profile: CHILL

      Plan: Advanced

      Run ID: 71823aa9-7c93-440b-a19d-e6fa84cdb5cf

      📥 Commits

      Reviewing files that changed from the base of the PR and between 9ff2ee3bbd02c3203d62e8bd777aacf860bcd18b and 2c6142fd3d4347ce538438ebb24b309f1c14f116.

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

      Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


      📝 Walkthrough

      Walkthrough

      The Vue QueryClient restores deprecated UseQueryOptions overloads for query, ensureQueryData, fetchQuery, and prefetchQuery. The methods continue to deep-unref options before delegation. Type tests cover reactive options and result types.

      Changes

      Vue QueryClient option compatibility

      Layer / File(s)Summary
      Restore options overloads and validate types
      packages/vue-query/src/queryClient.ts, packages/vue-query/src/__tests__/queryClient.test-d.ts, .changeset/vue-query-client-use-query-options.md
      The four methods add deprecated UseQueryOptions overloads and accept those options in their implementations. Type tests check reactive options, promise result types, and selected-data behavior. A patch changeset records the compatibility restoration.

      Priority: ➖ Normal

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

      Change: Bug fix · Severity of issue fixed: Medium

      Suggested reviewers: sukvvon

      Merge Risk: ⚪ Minimal · up to 2c614

      No actionable merge-blocking issue is established. Run the type tests as part of normal validation before merging.

      Security Architecture Review

      Security architecture risk: 🔵 Low · up to 2c614

      The restored overloads use the existing execution path, but they also accept an enabled option that does not stop an imperative call from fetching. This is a conditional risk for callers that mistake it for an execution guard; no privileged exposure was established.

      Retained concerns

      • Low · security · inferred: Restored overloads accept observer options containing enabled, but the imperative methods can still fetch and populate the cache when enabled is false. A downstream caller treating that option as an authorization or consent gate could initiate an unintended request; no such caller or privileged sink is evidenced here.
      Security review details

      Security Blast Radius

      • inferred — Any unintended fetch depends on a downstream application calling an imperative method with a query function and relying on enabled to suppress it. The inspected change adds no new credential, cross-service dependency, or alternate cache owner.

      Security Findings and Attack Paths

      • inferred — A conditional path exists if application-controlled state sets enabled to false while application code passes the options to an imperative method: that method may still execute its supplied query function. The evidence does not identify an attacker-controlled caller, sensitive destination, or authorization bypass in a consuming application.

      Trust Boundaries and Controls

      • observed — Deep-unref normalization and query-core execution remain the relevant boundaries. enabled describes observer automatic-refetch behavior, not a check in the imperative core paths.

      Hardening Proposals

      • proposed — Clarify that enabled is not an imperative execution or authorization guard. Callers handling sensitive queries should check the relevant authorization or consent condition before invoking these methods.
      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title clearly and specifically summarizes the main change: restoring UseQueryOptions support for the four Vue Query client methods.
      Description check✅ PassedThe description follows the required template, explains the change and motivation, completes all checklist items, and documents the release impact with a changeset.
      Linked Issues check✅ PassedThe change meets the coding requirements in [#11639]. QueryClient adds UseQueryOptions overloads for ensureQueryData, fetchQuery, and prefetchQuery. It also adds the related query overload…
      Out of Scope Changes check✅ PassedThe changed files are limited to the Vue Query client overloads, related type tests, and a patch changeset. The query overload uses the same UseQueryOptions compatibility fix as the directly requi…
      Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR

      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.
    2. DogPawHat reviewed

      @@ -314,2 +352,20 @@
      352+ TQueryKey,
      353+ TPageParam
      354+ >
      355+ >
      356+ | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>,
      314357 ): Promise<TData> {
      315- return super.query(cloneDeepUnref(options))
      358+ return super.query(
      359+ cloneDeepUnref(
      360+ options as MaybeRefDeep<
      361+ QueryExecuteOptions<
      362+ TQueryFnData,
      363+ TError,
      364+ TData,
      365+ TQueryData,
      366+ TQueryKey,
      367+ TPageParam
      368+ >
      369+ >,
      370+ ),
      371+ )

      If were doing a cast here, that indicates to me that QueryExecuteOptions is where we should fix this not in just the vue adapter.

    3. Hi, any update on this? We're still running into it on 5.104.5, since Orval's generated Vue query options can't be passed to queryClient.query. If there's anything I can help with to get this over the line, like addressing the review feedback, I'm happy to.

Sign in to join this conversation.