Skip to content

Conversation

hriday330
Copy link
Contributor

@hriday330 hriday330 commented Sep 9, 2025

Wrap all overloads of useInfiniteQueryOptions in MaybeRefOrGetter to support this pattern:

const options = {
  queryKey: ['infiniteQuery'],
  queryFn: () => sleep(0).then(() => 'Some data'),
  getNextPageParam: () => undefined,
  initialPageParam: 0,
};

const optionsWrappedComputed = computed(() => infiniteQueryOptions(options));

This should fix [vue-query] useInfiniteQuery doesn't support infiniteQueryOptions with MaybeRef type

Summary by CodeRabbit

  • New Features

    • Allow passing reactive/computed options (refs/getters) to base and infinite queries for improved reactivity and DX.
    • Add a helper to build infinite-query options more safely and conveniently.
  • Tests

    • Added tests ensuring reactive/computed options work with infinite queries and preserve correct result types.

Copy link
Contributor

coderabbitai bot commented Sep 9, 2025

Walkthrough

Updates TypeScript signatures so useBaseQuery and useInfiniteQuery accept MaybeRefOrGetter-wrapped options; adds an infiniteQueryOptions helper and two declaration tests verifying computed/plain options integrated via infiniteQueryOptions. No runtime behavior changes.

Changes

Cohort / File(s) Summary
Core hooks: MaybeRefOrGetter options support
packages/vue-query/src/useBaseQuery.ts, packages/vue-query/src/useInfiniteQuery.ts
Change: wrap options parameter types in MaybeRefOrGetter<...> for useBaseQuery and all useInfiniteQuery overloads/main signature; add MaybeRefOrGetter import in useBaseQuery. No runtime changes.
Helper: options builder
packages/vue-query/src/infiniteQueryOptions.ts
Add: exported infiniteQueryOptions(options) helper for constructing infinite-query options.
Tests: computed/plain options with helper
packages/vue-query/src/__tests__/useInfiniteQuery.test-d.tsx
Add: import infiniteQueryOptions and two tests asserting discriminated-union return types when passing computed(()=>infiniteQueryOptions(...)) and a plain function-returning infiniteQueryOptions(...) (wrapped via reactive()) into useInfiniteQuery.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I twitch my whiskers at typed delight,
Options may be refs, and that’s alright.
Infinite hops through pages I go,
With helpers in paws, the queries flow.
A nip of generics, a boundless spree—
Carrots cached, success for me! 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately and concisely describes the primary change — adding support for passing infiniteQueryOptions as a MaybeRef by updating useInfiniteQuery/type overloads — and is specific enough for a reviewer scanning history to understand the intent without extraneous detail.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee80ed9 and fe88f47.

📒 Files selected for processing (3)
  • packages/vue-query/src/__tests__/useInfiniteQuery.test-d.tsx (2 hunks)
  • packages/vue-query/src/useBaseQuery.ts (2 hunks)
  • packages/vue-query/src/useInfiniteQuery.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/vue-query/src/tests/useInfiniteQuery.test-d.tsx
  • packages/vue-query/src/useInfiniteQuery.ts
  • packages/vue-query/src/useBaseQuery.ts

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 and usage tips.

@hriday330 hriday330 marked this pull request as ready for review September 9, 2025 21:59
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/vue-query/src/__tests__/useInfiniteQuery.test-d.tsx (1)

100-112: Add a getter-based type test to cover MaybeRefOrGetter fully.

You validated computed(Ref) inputs; please also assert a plain getter (() => options) works, since the API now accepts MaybeRefOrGetter at the top level.

Apply this patch after Line 112:

+  it('should accept getter options using infiniteQueryOptions', () => {
+    const optionsGetter = () =>
+      infiniteQueryOptions({
+        queryKey: ['infiniteQuery'],
+        queryFn: () => sleep(0).then(() => 'Some data'),
+        getNextPageParam: () => undefined,
+        initialPageParam: 0,
+      })
+    const query = reactive(useInfiniteQuery(optionsGetter))
+    if (query.isSuccess) {
+      expectTypeOf(query.data).toEqualTypeOf<InfiniteData<string, unknown>>()
+    }
+  })
packages/vue-query/src/useInfiniteQuery.ts (1)

120-120: Tiny whitespace nit.

There’s an extra space before the comma.

Apply:

-export function useInfiniteQuery(
-  options: MaybeRefOrGetter<UseInfiniteQueryOptions> ,
+export function useInfiniteQuery(
+  options: MaybeRefOrGetter<UseInfiniteQueryOptions>,
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ccedf33 and cec9590.

📒 Files selected for processing (3)
  • packages/vue-query/src/__tests__/useInfiniteQuery.test-d.tsx (2 hunks)
  • packages/vue-query/src/useBaseQuery.ts (2 hunks)
  • packages/vue-query/src/useInfiniteQuery.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
packages/vue-query/src/useBaseQuery.ts (1)
packages/vue-query/src/types.ts (1)
  • MaybeRefOrGetter (27-27)
packages/vue-query/src/__tests__/useInfiniteQuery.test-d.tsx (2)
packages/vue-query/src/useInfiniteQuery.ts (1)
  • useInfiniteQuery (119-128)
packages/query-core/src/types.ts (1)
  • InfiniteData (204-207)
packages/vue-query/src/useInfiniteQuery.ts (3)
packages/vue-query/src/types.ts (1)
  • MaybeRefOrGetter (27-27)
packages/vue-query/src/infiniteQueryOptions.ts (2)
  • DefinedInitialDataInfiniteOptions (26-42)
  • UndefinedInitialDataInfiniteOptions (10-24)
packages/react-query/src/useInfiniteQuery.ts (1)
  • useInfiniteQuery (72-81)
🔇 Additional comments (6)
packages/vue-query/src/__tests__/useInfiniteQuery.test-d.tsx (1)

5-5: Import looks good.

Path resolution is correct for local test usage.

packages/vue-query/src/useBaseQuery.ts (1)

25-25: Type import alignment is fine.

packages/vue-query/src/useInfiniteQuery.ts (4)

75-82: Overload now accepts MaybeRefOrGetter — good.

This unblocks passing computed/refs for the “defined initialData” branch.


92-99: Overload now accepts MaybeRefOrGetter — good.

Covers the default/undefined initialData path consistently.


109-116: Generic overload with MaybeRefOrGetter — good.

Keeps inference parity while extending accepted inputs.


119-127: No changes needed for infiniteQueryOptions export
infiniteQueryOptions is already re-exported from packages/vue-query/src/index.ts (line 9).

Comment on lines 62 to 70
options: MaybeRefOrGetter<UseQueryOptionsGeneric<
TQueryFnData,
TError,
TData,
TQueryData,
TQueryKey,
TPageParam
>,
>>,
queryClient?: QueryClient,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Unwrap MaybeRefOrGetter at the call site to avoid stale options.

Now that options can be a getter, ensure it’s evaluated before deep-unref so dependencies are tracked and runtime receives an object, not a function.

Apply this change outside the shown hunk:

  • Import toValue from vue-demi with the other imports.
  • Evaluate options via toValue before cloneDeepUnref.

Example changes:

-  computed,
+  computed,
+  toValue,
-    const clonedOptions = cloneDeepUnref(options as any)
+    const clonedOptions = cloneDeepUnref(toValue(options) as any)

Run to confirm utils already handles getters (if so, the toValue change is optional; if not, it’s required):


🏁 Script executed:

#!/bin/bash
# Verify cloneDeepUnref unwraps getters internally; if not, prefer toValue(options) at call site.
rg -n --glob 'packages/vue-query/src/**' 'cloneDeepUnref\(' -C2
rg -n --glob 'packages/vue-query/src/**' '\btoValue\b' -C2
# Sanity-check: ensure no places still assume options is non-function
rg -n --glob 'packages/vue-query/src/**' 'typeof clonedOptions\.enabled === .function.'

Length of output: 14628


Import toValue and unwrap options before cloning

  • Add toValue from vue-demi alongside your computed import.
  • Change
    const clonedOptions = cloneDeepUnref(options as any)
    to
    const clonedOptions = cloneDeepUnref(toValue(options) as any)

to ensure any getter passed in options is invoked before deep-unref.

🤖 Prompt for AI Agents
In packages/vue-query/src/useBaseQuery.ts around lines 62 to 70, options may be
a getter/ref and is being deep-unrefbed without first invoking it; import
toValue from 'vue-demi' alongside the existing computed import and replace the
cloneDeepUnref(options as any) call with cloneDeepUnref(toValue(options) as any)
so any getter is evaluated before cloning/unwrapping.

Copy link

nx-cloud bot commented Sep 14, 2025

View your CI Pipeline Execution ↗ for commit f42ddf2

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 1m 21s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 20s View ↗

☁️ Nx Cloud last updated this comment at 2025-09-22 06:38:07 UTC

Copy link

pkg-pr-new bot commented Sep 14, 2025

More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@9634

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@9634

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@9634

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@9634

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@9634

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@9634

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@9634

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@9634

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@9634

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@9634

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@9634

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@9634

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@9634

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@9634

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@9634

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@9634

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@9634

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@9634

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@9634

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@9634

commit: f42ddf2

Copy link

codecov bot commented Sep 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.10%. Comparing base (cd4ef5c) to head (f42ddf2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #9634       +/-   ##
===========================================
+ Coverage   46.38%   71.10%   +24.71%     
===========================================
  Files         214       19      -195     
  Lines        8488      481     -8007     
  Branches     1919      139     -1780     
===========================================
- Hits         3937      342     -3595     
+ Misses       4108      109     -3999     
+ Partials      443       30      -413     
Components Coverage Δ
@tanstack/angular-query-experimental ∅ <ø> (∅)
@tanstack/eslint-plugin-query ∅ <ø> (∅)
@tanstack/query-async-storage-persister ∅ <ø> (∅)
@tanstack/query-broadcast-client-experimental ∅ <ø> (∅)
@tanstack/query-codemods ∅ <ø> (∅)
@tanstack/query-core ∅ <ø> (∅)
@tanstack/query-devtools ∅ <ø> (∅)
@tanstack/query-persist-client-core ∅ <ø> (∅)
@tanstack/query-sync-storage-persister ∅ <ø> (∅)
@tanstack/query-test-utils ∅ <ø> (∅)
@tanstack/react-query ∅ <ø> (∅)
@tanstack/react-query-devtools ∅ <ø> (∅)
@tanstack/react-query-next-experimental ∅ <ø> (∅)
@tanstack/react-query-persist-client ∅ <ø> (∅)
@tanstack/solid-query ∅ <ø> (∅)
@tanstack/solid-query-devtools ∅ <ø> (∅)
@tanstack/solid-query-persist-client ∅ <ø> (∅)
@tanstack/svelte-query ∅ <ø> (∅)
@tanstack/svelte-query-devtools ∅ <ø> (∅)
@tanstack/svelte-query-persist-client ∅ <ø> (∅)
@tanstack/vue-query 71.10% <ø> (ø)
@tanstack/vue-query-devtools ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hriday330
Copy link
Contributor Author

@TkDodo @arnoud-dv @DamianOsipiuk Can you please review this when you have a moment?

@DamianOsipiuk DamianOsipiuk merged commit 49243c8 into TanStack:main Sep 22, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[vue-query] useInfiniteQuery doesn't support infiniteQueryOptions with MaybeRef type
2 participants