Skip to content

Conversation

hriday330
Copy link

@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

    • Pass reactive/computed options (ref/getter) to infinite and base queries for improved reactivity and DX.
    • Added a helper to construct infinite query options more safely and conveniently.
  • Tests

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

Copy link
Contributor

coderabbitai bot commented Sep 9, 2025

Walkthrough

Updates type signatures of useBaseQuery and useInfiniteQuery to accept MaybeRefOrGetter-wrapped options. Adds a new helper infiniteQueryOptions. Extends tests to validate computed/plain options with infiniteQueryOptions and ensure correct discriminated-union behavior for useInfiniteQuery. No runtime logic changes reported.

Changes

Cohort / File(s) Summary
Core hooks: MaybeRefOrGetter options support
packages/vue-query/src/useBaseQuery.ts, packages/vue-query/src/useInfiniteQuery.ts
Wraps options parameters in MaybeRefOrGetter<...> across useBaseQuery and all useInfiniteQuery overloads and main signature; adds MaybeRefOrGetter import in useBaseQuery. No runtime changes.
Helper: options builder
packages/vue-query/src/infiniteQueryOptions.ts
Adds infiniteQueryOptions(options) function for constructing infinite query options (new exported helper).
Tests: computed/plain options with helper
packages/vue-query/src/__tests__/useInfiniteQuery.test-d.tsx
Imports infiniteQueryOptions and adds two tests: one passing computed(()=>infiniteQueryOptions(...)) via reactive() and one passing plain function-returning infiniteQueryOptions(...) via reactive() to useInfiniteQuery; both assert discriminated-union return type (InfiniteData<...>) on success.

Sequence Diagram(s)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks (2 passed, 1 warning)

❌ 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 succinctly describes the primary change in the pull request by indicating that infiniteQueryOptions now supports MaybeRef arguments in the vue-query package. It follows conventional commit style, is concise, and focuses on the main fix without extraneous detail.

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! 🥕✨

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


📜 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 cec9590 and ee80ed9.

📒 Files selected for processing (2)
  • packages/vue-query/src/__tests__/useInfiniteQuery.test-d.tsx (2 hunks)
  • packages/vue-query/src/useInfiniteQuery.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/vue-query/src/useInfiniteQuery.ts
  • packages/vue-query/src/tests/useInfiniteQuery.test-d.tsx
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

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
1 participant