Skip to content

fix(vue-query): accept getters of query-core options in useQuery and useInfiniteQuery - #10

Closed
benjavicente wants to merge 7 commits into
query-mutation-options-in-corefrom
vue-shared-query-options
Closed

benjavicente wants to merge 7 commits into
query-mutation-options-in-corefrom
vue-shared-query-options

Conversation

@benjavicente

@benjavicente benjavicente commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

🎯 Changes

Lets useQuery and useInfiniteQuery accept a getter of options from @tanstack/query-core, the same way the other adapters take them, so Vue gets the shared options from TanStack#10973. useQueries, useMutation, and the imperative client already accept them directly, and this adds tests for those.

const options = queryOptions({ queryKey, queryFn }) // from @tanstack/query-core
useQuery(() => options)
  • New overloads keep the key bare, so TQueryKey is inferred from core's callbacks. DeepUnwrapRef breaks tagged keys, and Query is invariant in its key.
  • They only accept getters, and come after the Vue overloads, so options those accept resolve as before. The Vue fallback is repeated last to keep Parameters<typeof useQuery>.
  • A key containing a ref is rejected, because callbacks receive the unwrapped key at runtime.
  • Types only: emitted JS is unchanged.

Two recent changes on main made this possible: TanStack#12542 is the runtime change this needed, since Vue now passes the query to enabled(query) callbacks, and TanStack#12525 also improved the types for shared options in the imperative client methods.

Limits: useQuery(coreOptions) without a getter stays rejected before TS 7.1. Generic keys such as ['todo', id] with id: T stay rejected, as on main. A getter function inside a core key isn't rejected.

✅ 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.
  • This change is docs/CI/dev-only (no release).

Fork review PR, stacked on query-mutation-options-in-core. The description needs rewriting in your own voice before opening upstream, per AI_POLICY.md.

🤖 Generated with Claude Code

…Query

Options from query-core carry a tagged key, which DeepUnwrapRef turns into
an object, and Query is invariant in its key type. New overloads keep the key
bare so it is inferred from the callbacks.

They come after the Vue overloads, so options those accept resolve as before.
The Vue fallback is repeated last to keep `Parameters<typeof useQuery>`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

🚀 Changeset Version Preview

2 package(s) bumped directly, 22 bumped as dependents.

🟨 Minor bumps

Package Version Reason
@tanstack/query-core 5.107.1 → 5.108.0 Changeset
@tanstack/vue-query 5.107.1 → 5.108.0 Changeset
@tanstack/angular-query-experimental 5.107.1 → 5.108.0 Dependent
@tanstack/eslint-plugin-query 5.107.1 → 5.108.0 Dependent
@tanstack/preact-query 5.107.1 → 5.108.0 Dependent
@tanstack/preact-query-devtools 5.107.1 → 5.108.0 Dependent
@tanstack/preact-query-persist-client 5.107.1 → 5.108.0 Dependent
@tanstack/query-async-storage-persister 5.107.1 → 5.108.0 Dependent
@tanstack/query-broadcast-client-experimental 5.107.1 → 5.108.0 Dependent
@tanstack/query-devtools 5.107.1 → 5.108.0 Dependent
@tanstack/query-persist-client-core 5.107.1 → 5.108.0 Dependent
@tanstack/query-sync-storage-persister 5.107.1 → 5.108.0 Dependent
@tanstack/react-query 5.107.1 → 5.108.0 Dependent
@tanstack/react-query-devtools 5.107.1 → 5.108.0 Dependent
@tanstack/react-query-next-experimental 5.107.1 → 5.108.0 Dependent
@tanstack/react-query-persist-client 5.107.1 → 5.108.0 Dependent
@tanstack/solid-query 5.107.1 → 5.108.0 Dependent
@tanstack/solid-query-devtools 5.107.1 → 5.108.0 Dependent
@tanstack/solid-query-persist-client 5.107.1 → 5.108.0 Dependent

🟩 Patch bumps

Package Version Reason
@tanstack/lit-query 0.2.38 → 0.2.39 Dependent
@tanstack/svelte-query 6.4.1 → 6.4.2 Dependent
@tanstack/svelte-query-devtools 6.4.1 → 6.4.2 Dependent
@tanstack/svelte-query-persist-client 6.4.1 → 6.4.2 Dependent
@tanstack/vue-query-devtools 6.4.1 → 6.4.2 Dependent

Accepting plain objects, refs and computeds let options the Vue overloads reject
fall through, so callbacks typed with a ref in the key compiled even though they
receive the unwrapped key at runtime. Getters are also how the other adapters
take reactive options, and a key containing a ref is now rejected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@benjavicente benjavicente changed the title fix(vue-query): accept query-core options in useQuery and useInfiniteQuery fix(vue-query): accept getters of query-core options in useQuery and useInfiniteQuery Nov 7, 2026
benjavicente and others added 5 commits November 7, 2026 08:33
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Checking that the key was assignable to its unwrapped type let `Ref<object>`
through, since a Ref is an object. Checking the other direction catches it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`@tanstack/vue-query` is in the same fixed group as `@tanstack/query-core`, so
it takes the same minor bump. The docs section is left out of this change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A zero-argument `enabled` is a Vue getter, so its cached result goes stale for
state Vue doesn't track, and `cloneDeep` overflows on cyclic objects and skips
symbol keys. Comments mark both where they happen, and an `it.fails` test states
the wanted `enabled` behaviour, so it goes red once that is fixed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The comments are enough for a case this rare.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@benjavicente

Copy link
Copy Markdown
Owner Author

Landed on query-mutation-options-in-core as two commits.

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.

1 participant