Skip to content

FetchQueries and FetchInfiniteQueries - #89

Open
js2me wants to merge 9 commits into
masterfrom
feature/fetch-queries
Open

FetchQueries and FetchInfiniteQueries#89
js2me wants to merge 9 commits into
masterfrom
feature/fetch-queries

Conversation

@js2me

@js2me js2me commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Summary by cubic

Add FetchQuery and FetchInfiniteQuery for first-class HTTP queries with MobX reactivity and simple params. Also adds presets and global QueryClient.fetchQueries defaults, with docs, types, and tests.

  • New Features

    • FetchQuery/FetchInfiniteQuery with declarative params, function-based configs that track MobX observables, and start({ params }).
    • Auto queryKey; makeFetchRequest builds URLs, merges headers, handles JSON/native bodies, 404→null, responseType, abort/timeout, credentials/mode, and per-client defaults.
    • Global defaults via QueryClient.fetchQueries (baseUrl, headers, customFetch, transformResponse, throwOnError, timeout, credentials, mode, meta); presets createFetchQuery/createFetchInfiniteQuery auto-mount the client and accept options or a function; new API/preset pages and error guides (How to define the type of Meta #1, [Feature Request] Add queryOptions function #2), plus inference/config-from-fn types and exports.
  • Bug Fixes

    • Type export/overload fixes; shared preset instance creator for consistent one-time client mount; exclude tests from build.

Written for commit ef6feeb. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features

    • Added fetch-based queries and infinite queries with reactive parameters, pagination, request customization, cancellation, response transformation, and error handling.
    • Added factory presets for creating fetch queries and infinite queries.
    • Added global fetch configuration through the query client, including base URLs, headers, custom fetch behavior, and timeouts.
    • Added manual query start support and stable pagination-independent query keys.
  • Documentation

    • Expanded API guides for fetch queries, infinite queries, presets, configuration, type helpers, and troubleshooting errors.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds reactive FetchQuery and FetchInfiniteQuery wrappers, shared fetch execution and client defaults, factory presets, public exports, tests, documentation, and release/build configuration updates.

Changes

Fetch query support

Layer / File(s) Summary
Client configuration and request execution
src/query-client*, src/utils/make-fetch-request.ts
Adds fetchQueries defaults and shared request execution with URL construction, headers, bodies, cancellation, timeout, response handling, and transforms.
FetchQuery implementation
src/fetch-query.ts
Adds typed request parameters, query-key serialization, reactive configuration, error handling, and manual start() support.
FetchInfiniteQuery pagination
src/fetch-infinite-query.ts
Adds page-aware parameters, pagination-independent query keys, constructors, request execution, and page-aware start() support.
Presets and public exports
src/preset/*, src/index.ts, src/inifinite-query.types.ts
Adds shared instance factories, fetch-query presets, one-time client mounting, public exports, and InfiniteQueryLike.
Fetch query and preset validation
src/*.test.ts, src/preset/*test.ts
Tests request behavior, pagination, client defaults, reactivity, cancellation, overload typing, and preset construction.
Documentation and release configuration
docs/*, .github/workflows/*, package.json, tsconfig*.json, scripts/*, .changeset/*
Documents the APIs, presets, errors, configuration, and type helpers. Updates publishing, package, build, and script configuration.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant FetchQuery
  participant QueryClient
  participant makeFetchRequest
  participant Fetch
  FetchQuery->>QueryClient: resolve fetchQueries defaults
  FetchQuery->>makeFetchRequest: pass fetch parameters and signal
  makeFetchRequest->>Fetch: issue HTTP request
  Fetch-->>makeFetchRequest: return response
  makeFetchRequest-->>FetchQuery: return parsed or transformed data
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding FetchQuery and FetchInfiniteQuery APIs.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fetch-queries

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

Choose a reason for hiding this comment

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

Actionable comments posted: 12

🧹 Nitpick comments (3)
src/preset/create-fetch-query.ts (1)

31-50: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extracting shared factory logic to reduce duplication.

The implementation of createFetchQuery (lines 31-50) is nearly identical to createFetchInfiniteQuery (lines 80-99) — same args-length dispatch, same function-vs-object wrapping, same mountQueryClientOnce(getQueryClient(...)) pattern. A shared helper could eliminate this duplication and ensure both factories stay in sync as the pattern evolves.

♻️ Optional: shared factory helper
+// src/preset/create-query-factory.ts
+import {
+  type AnyQueryClient,
+  getQueryClient,
+  mountQueryClientOnce,
+} from 'mobx-tanstack-query';
+import { queryClient } from './query-client.js';
+
+export function createQueryFactory<T extends new (...args: any[]) => any>(
+  QueryClass: T,
+): (...args: [any, any?]) => InstanceType<T> {
+  return (...args) => {
+    let instance: InstanceType<T>;
+    if (args.length === 2) {
+      instance = new QueryClass(
+        args[0],
+        typeof args[1] === 'function' ? args[1] : () => args[1],
+      );
+    } else {
+      const options = args[0];
+      instance = new QueryClass({
+        ...options,
+        queryClient: options.queryClient ?? queryClient,
+      });
+    }
+    mountQueryClientOnce(getQueryClient(instance));
+    return instance;
+  };
+}

Then each factory becomes a one-liner delegation.

🤖 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 `@src/preset/create-fetch-query.ts` around lines 31 - 50, Extract the shared
argument-dispatch and query-client mounting logic from createFetchQuery and
createFetchInfiniteQuery into a reusable factory helper. Preserve each factory’s
existing FetchQuery/FetchInfiniteQuery construction behavior, including
function-versus-object wrapping and default queryClient handling, then delegate
both factories through the helper so the
mountQueryClientOnce(getQueryClient(...)) flow is centralized.
src/preset/create-fetch-query.test.ts (1)

64-107: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Minor duplication between "returns FetchQuery instance from options overload" and "uses preset queryClient when not provided".

Lines 64-72 and 85-94 are functionally identical — both create a query without an explicit queryClient, assert instanceof FetchQuery, and call destroy(). Consider consolidating or making the second test verify the preset client is actually used rather than just checking the instance type.

🤖 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 `@src/preset/create-fetch-query.test.ts` around lines 64 - 107, Remove the
redundant “uses preset queryClient when not provided” coverage or change it to
assert that the preset queryClient is actually used, while retaining the
instance and cleanup assertions in “returns FetchQuery instance from options
overload.”
src/preset/create-fetch-infinite-query.test.ts (1)

96-146: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Minor duplication between "returns FetchInfiniteQuery instance from options overload" and "uses preset queryClient when not provided".

Lines 96-106 and 121-131 both create a query without an explicit queryClient, assert instanceof FetchInfiniteQuery, and call destroy(). They are functionally identical. Consider consolidating or differentiating the second test to verify the preset client is actually used (e.g., by checking query.options.queryClient or similar).

🤖 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 `@src/preset/create-fetch-infinite-query.test.ts` around lines 96 - 146, Remove
the duplicate coverage between “returns FetchInfiniteQuery instance from options
overload” and “uses preset queryClient when not provided” by changing the latter
to assert that the preset query client is actually selected. Keep the instance
assertion in the overload test, and use the query’s exposed options or
equivalent client reference in the preset-client test before destroying the
query.
🤖 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 @.github/workflows/version-or-publish.yml:
- Around line 49-61: Add NODE_AUTH_TOKEN to the env configuration of the
changesets/action step identified by id pub-or-release-pr, sourcing it from the
repository’s npm authentication secret. Preserve the existing GITHUB_TOKEN and
publishing configuration so pnpm pub can authenticate with the npm registry.

In `@docs/api/FetchQuery.md`:
- Around line 79-80: Update the FetchQuery documentation’s headers option to use
the complete Record type arguments, changing it to Record<string, string>;
retain Record<string, unknown> for object request bodies.
- Line 34: Update the petId observable declaration to initialize the MobX box
with a value, using undefined with a string-or-undefined type or an appropriate
concrete pet ID. Preserve the existing petId usage and documentation context.

In `@docs/api/QueryClient.md`:
- Line 101: Update the headers option type in the QueryClient API documentation
from Record<string> to Record<string, string>, keeping the existing description
and behavior unchanged.

In `@docs/errors/2.md`:
- Around line 37-40: Update the params callback to serialize the cursor in the
request, using the existing cursor value as a query parameter or interpolating
it into the path; do not return it as pageParam, which is only the callback
argument. Preserve the null return when no cursor is available.

In `@src/fetch-infinite-query.ts`:
- Around line 36-70: Unify the page-data type in FetchInfiniteQueryConfig and
the related fetchInfiniteQuery flow: make the pagination callbacks,
InfiniteQuery configuration, and select input use the actual makeFetchRequest
result type, TOutputData | null, instead of the independent TQueryFnData type.
Remove the incompatible output generic or propagate the unified type through the
parent query configuration, including the implementations referenced around the
additional affected ranges.
- Around line 73-93: Update FetchInfiniteQueryPositionalConfig to redeclare
initialPageParam, getNextPageParam, and getPreviousPageParam after omitting them
from InfiniteQueryConfig, using the same types and optionality as the
corresponding pagination options. Keep the existing params and select
definitions unchanged so positional overloads accept pagination configuration.

In `@src/fetch-query.ts`:
- Around line 38-47: Include throwOnError in FetchQueryKeyMeta and update
parseFetchQueryKey() to reconstruct it from the query key, preserving the
query-specified value instead of falling back to the client default. Apply the
same round-trip change to the infinite-query key handling identified by the
related ranges.
- Around line 31-34: Update the select/transform callback contract in
fetch-query.ts so its input type includes null when notFoundAsNull is enabled,
matching makeFetchRequest()’s reachable result. Propagate this nullable type
through the option definition and the related callback invocation/type
declarations at the referenced sections, while preserving non-null typing when
the option is disabled.
- Around line 121-140: Update buildFetchQueryKey and buildFetchInfiniteQueryKey
to avoid placing raw BodyInit values in query metadata. Derive and store a
stable bodyKey by serializing supported body types explicitly, ensuring distinct
FormData, Blob, ReadableStream, URLSearchParams, ArrayBuffer, and similar
payloads produce distinct TanStack cache keys; preserve the existing key
structure and request behavior.

In `@src/utils/make-fetch-request.ts`:
- Around line 84-90: Update the non-OK response handling in makeFetchRequest so
throwOnError raises the advertised exported DefaultError (or a suitable exported
Error subclass) instead of throwing the raw Response, while preserving the
response status/details on the error for callers that need them. Keep the
notFoundAsNull 404 behavior unchanged and ensure the public error type matches
the thrown value.
- Around line 60-68: Update the timeout handling around
abortControllerWithTimeout so an already-aborted signal is propagated
immediately before issuing the request. Check the incoming signal state and
abort the combined controller when necessary, while preserving the existing
abort listeners and timeout behavior for signals that are not yet aborted.

---

Nitpick comments:
In `@src/preset/create-fetch-infinite-query.test.ts`:
- Around line 96-146: Remove the duplicate coverage between “returns
FetchInfiniteQuery instance from options overload” and “uses preset queryClient
when not provided” by changing the latter to assert that the preset query client
is actually selected. Keep the instance assertion in the overload test, and use
the query’s exposed options or equivalent client reference in the preset-client
test before destroying the query.

In `@src/preset/create-fetch-query.test.ts`:
- Around line 64-107: Remove the redundant “uses preset queryClient when not
provided” coverage or change it to assert that the preset queryClient is
actually used, while retaining the instance and cleanup assertions in “returns
FetchQuery instance from options overload.”

In `@src/preset/create-fetch-query.ts`:
- Around line 31-50: Extract the shared argument-dispatch and query-client
mounting logic from createFetchQuery and createFetchInfiniteQuery into a
reusable factory helper. Preserve each factory’s existing
FetchQuery/FetchInfiniteQuery construction behavior, including
function-versus-object wrapping and default queryClient handling, then delegate
both factories through the helper so the
mountQueryClientOnce(getQueryClient(...)) flow is centralized.
🪄 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: d23dff83-a471-489f-9a40-2bcabf265ffb

📥 Commits

Reviewing files that changed from the base of the PR and between 3129689 and 580d2cf.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (29)
  • .changeset/wet-turtles-relax.md
  • .github/workflows/version-or-publish.yml
  • docs/.vitepress/config.mts
  • docs/api/FetchInfiniteQuery.md
  • docs/api/FetchQuery.md
  • docs/api/QueryClient.md
  • docs/api/other.md
  • docs/errors/1.md
  • docs/errors/2.md
  • docs/preset/createFetchInfiniteQuery.md
  • docs/preset/createFetchQuery.md
  • docs/preset/index.md
  • package.json
  • scripts/prepare-dist.ts
  • src/fetch-infinite-query.ts
  • src/fetch-query.test.ts
  • src/fetch-query.ts
  • src/index.ts
  • src/inifinite-query.types.ts
  • src/preset/create-fetch-infinite-query.test.ts
  • src/preset/create-fetch-infinite-query.ts
  • src/preset/create-fetch-query.test.ts
  • src/preset/create-fetch-query.ts
  • src/preset/index.ts
  • src/query-client.ts
  • src/query-client.types.ts
  • src/utils/make-fetch-request.ts
  • tsconfig.json
  • tsconfig.test.json

Comment thread .github/workflows/version-or-publish.yml
Comment thread docs/api/FetchQuery.md
Comment thread docs/api/FetchQuery.md Outdated
Comment thread docs/api/QueryClient.md Outdated
Comment thread docs/errors/2.md
Comment thread src/fetch-query.ts
Comment thread src/fetch-query.ts
Comment thread src/fetch-query.ts
Comment thread src/utils/make-fetch-request.ts
Comment thread src/utils/make-fetch-request.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

7 issues found across 30 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/utils/make-fetch-request.ts">

<violation number="1" location="src/utils/make-fetch-request.ts:23">
P1: Per-request `params.throwOnError` is ignored for both fetch query types, so `throwOnError: false` still throws unless the client default is also false. Preserve this field when constructing/parsing the fetch key (or pass it separately like `transformResponse`).</violation>

<violation number="2" location="src/utils/make-fetch-request.ts:60">
P2: A configured `timeout: 0` disables timeout handling instead of aborting immediately. Check for `null`/`undefined` rather than truthiness so zero remains a valid millisecond timeout.</violation>

<violation number="3" location="src/utils/make-fetch-request.ts:90">
P2: This throws a raw `Response` object, which lacks `Error.message` and `.stack` properties. The query wrappers (`FetchQuery`, `FetchInfiniteQuery`) type their error as `DefaultError`, so error handlers receiving this value will encounter a type mismatch. Consider throwing a custom `Error` subclass that wraps the response (e.g., `class FetchError extends Error { response: Response }`) or updating the public error type to include `Response`.</violation>
</file>

<file name="package.json">

<violation number="1" location="package.json:14">
P1: The `changeset:version` script added to package.json references `bash scripts/changeset-version.sh`, but that file does not exist in the repository. The `scripts/` directory only contains `prepare-dist.ts`. Running `pnpm changeset:version` will fail with a "No such file or directory" error. Either create the `scripts/changeset-version.sh` file, or if the intent was to run the direct changeset command, change the script to `pnpm changeset version` or remove it if it's not needed.</violation>
</file>

<file name="src/fetch-query.ts">

<violation number="1" location="src/fetch-query.ts:63">
P2: The `select` callback is typed as receiving `TOutputData`, but `makeFetchRequest` can return `null` when `notFoundAsNull` is `true` and the response is 404. This means a `select` function that TypeScript considers type-safe could receive `null` at runtime, leading to unexpected crashes. Consider typing this as `(data: TOutputData | null) => TData`.</violation>
</file>

<file name="docs/api/other.md">

<violation number="1" location="docs/api/other.md:3">
P1: The types `InferFetchQuery` and `InferFetchInfiniteQuery` are documented in the heading and code example but don't exist anywhere in the source code. Users importing them will get TS errors. Add the missing type definitions (analogous to `InferQuery`/`InferInfiniteQuery`) or remove the docs references.</violation>
</file>

<file name="docs/errors/2.md">

<violation number="1" location="docs/errors/2.md:10">
P2: All three code examples use `new FetchInfiniteQuery(queryClient, { params: ..., initialPageParam: 0, getNextPageParam: ... })` but the positional config (`FetchInfiniteQueryPositionalConfig`) does not accept `initialPageParam`, `getNextPageParam`, or `getPreviousPageParam` — they're only valid in the single-arg config form. Copying these examples would cause TypeScript type errors. Suggest switching all examples to the single-arg form: `new FetchInfiniteQuery({ queryClient, params: ..., initialPageParam: ..., getNextPageParam: ... })`.</violation>
</file>

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

Comment thread src/fetch-query.ts
Comment thread .github/workflows/version-or-publish.yml
Comment thread src/fetch-query.ts
Comment thread src/preset/create-fetch-infinite-query.ts Outdated
Comment thread docs/api/other.md
Comment thread docs/api/FetchQuery.md Outdated
Comment thread docs/api/QueryClient.md Outdated
Comment thread docs/errors/1.md
Comment thread src/preset/create-fetch-infinite-query.test.ts
Comment thread docs/preset/createFetchInfiniteQuery.md

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 5 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/fetch-infinite-query.ts Outdated
Comment thread src/fetch-query.ts
Comment thread src/fetch-infinite-query.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (4)
docs/api/FetchQuery.md (2)

28-56: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Initialize the MobX box with a value. observable.box<string>() needs an initial value — use observable.box<string | undefined>(undefined).

🤖 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 `@docs/api/FetchQuery.md` around lines 28 - 56, Update the Dynamic params
example’s petId declaration to initialize the MobX box with undefined, using the
string-or-undefined type so the existing falsy-value query disabling behavior
remains valid.

58-101: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use complete Record type arguments. Record<string> on line 93 is invalid TypeScript; document headers as Record<string, string>.

🤖 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 `@docs/api/FetchQuery.md` around lines 58 - 101, Update the headers field in
the FetchQueryParams documentation to use the complete Record type, specifying
string keys and string values as Record<string, string>.
src/fetch-infinite-query.ts (2)

104-107: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

FetchInfiniteQueryPositionalConfig still omits pagination options.

This interface omits initialPageParam, getNextPageParam, and getPreviousPageParam (lines 100–102) without redeclaring them. The positional constructor overload (new FetchInfiniteQuery(queryClient, config)) therefore rejects the pagination configuration required for infinite queries. The past review marked this as addressed in commit f14fce0, but the current code retains the same omission.

Proposed fix
 export interface FetchInfiniteQueryPositionalConfig<
   TQueryFnData = unknown,
   TError = DefaultError,
   TPageParam = unknown,
   TData = InfiniteData<TQueryFnData, TPageParam>,
   TOutputData = any,
-> extends Omit<
-    Partial<InfiniteQueryConfig<TQueryFnData, TError, TPageParam, TData, any>>,
-    | 'queryFn'
-    | 'queryKey'
-    | 'options'
-    | 'select'
-    | 'initialPageParam'
-    | 'getNextPageParam'
-    | 'getPreviousPageParam'
-  > {
-  params?: MaybeFn<
-    MaybeFalsy<FetchInfiniteQueryParams<TOutputData, TPageParam>>
-  >;
-  select?: (data: InfiniteData<TQueryFnData, TPageParam>) => TData;
-}
+> extends Omit<
+    FetchInfiniteQueryConfig<
+      TQueryFnData,
+      TError,
+      TPageParam,
+      TData,
+      TOutputData
+    >,
+    'queryClient'
+  > {}
🤖 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 `@src/fetch-infinite-query.ts` around lines 104 - 107, Update
FetchInfiniteQueryPositionalConfig to include the infinite-query pagination
options initialPageParam, getNextPageParam, and getPreviousPageParam, matching
the corresponding configuration interface. Ensure the positional constructor
overload accepts these options while preserving the existing params and select
properties.

82-85: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Type inconsistency between TOutputData and TQueryFnData persists.

select (line 85) and pagination callbacks (lines 70–75) use TQueryFnData, but queryFn (line 300) returns TOutputData | null from makeFetchRequest<TOutputData>. When callers specify different TQueryFnData and TOutputData generics, the compiler accepts incompatible types and runtime values contradict the type signatures. This was previously flagged and remains unresolved.

🤖 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 `@src/fetch-infinite-query.ts` around lines 82 - 85, Align the generic data
types throughout fetchInfiniteQuery so the queryFn result from
makeFetchRequest<TOutputData> matches the type used by select and the pagination
callbacks. Update the related InfiniteData and callback signatures to use the
same output type, or enforce the generic relationship so incompatible
TQueryFnData and TOutputData combinations are rejected.
🤖 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 `@docs/api/FetchInfiniteQuery.md`:
- Around line 30-67: Update the “How it works” description for
`FetchInfiniteQuery` so `data` is documented as an `InfiniteData` object
containing `pages` and `pageParams`, with fetched results accessed through
`data.pages` rather than directly as an array.

---

Duplicate comments:
In `@docs/api/FetchQuery.md`:
- Around line 28-56: Update the Dynamic params example’s petId declaration to
initialize the MobX box with undefined, using the string-or-undefined type so
the existing falsy-value query disabling behavior remains valid.
- Around line 58-101: Update the headers field in the FetchQueryParams
documentation to use the complete Record type, specifying string keys and string
values as Record<string, string>.

In `@src/fetch-infinite-query.ts`:
- Around line 104-107: Update FetchInfiniteQueryPositionalConfig to include the
infinite-query pagination options initialPageParam, getNextPageParam, and
getPreviousPageParam, matching the corresponding configuration interface. Ensure
the positional constructor overload accepts these options while preserving the
existing params and select properties.
- Around line 82-85: Align the generic data types throughout fetchInfiniteQuery
so the queryFn result from makeFetchRequest<TOutputData> matches the type used
by select and the pagination callbacks. Update the related InfiniteData and
callback signatures to use the same output type, or enforce the generic
relationship so incompatible TQueryFnData and TOutputData combinations are
rejected.
🪄 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: 31b775b9-00ed-4e39-86e6-eb7f2a383866

📥 Commits

Reviewing files that changed from the base of the PR and between 580d2cf and 91ac7db.

📒 Files selected for processing (7)
  • docs/api/FetchInfiniteQuery.md
  • docs/api/FetchQuery.md
  • package.json
  • src/fetch-infinite-query.ts
  • src/fetch-query.ts
  • src/preset/create-fetch-query.test.ts
  • src/preset/create-fetch-query.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/preset/create-fetch-query.ts
  • package.json
  • src/fetch-query.ts

Comment thread docs/api/FetchInfiniteQuery.md

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/preset/createFetchInfiniteQuery.md (1)

51-51: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Replace the internal source-file link.

Line 51 links to /src/utils/mount-query-client-once.ts. This is a repository source path, not a documented VitePress page. Unless custom source-file routing exists, the published link will return 404. Link to a stable documentation page or repository source URL instead.

🤖 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 `@docs/preset/createFetchInfiniteQuery.md` at line 51, Replace the internal
source-file link to mount-query-client-once.ts in the createFetchInfiniteQuery
documentation with a stable documentation URL or repository source URL that
resolves correctly in the published site.
🧹 Nitpick comments (1)
src/preset/create-fetch-query.test.ts (1)

305-308: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Both refetch tests allocate the QueryClient inside the reactive config function. The config function re-runs when the observable changes, so each evaluation returns a new QueryClient. A per-evaluation client defeats the query cache, and mountQueryClientOnce mounts only the first instance. Both tests still pass because they assert only the fetch count and the response data, so they hide this path instead of verifying refetching on a stable client.

  • src/preset/create-fetch-query.test.ts#L305-L308: create the QueryClient once outside the config function and reference it inside.
  • src/preset/create-fetch-infinite-query.test.ts#L283-L288: apply the same change to the infinite-query refetch test.
🤖 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 `@src/preset/create-fetch-query.test.ts` around lines 305 - 308, Both refetch
tests create a new QueryClient on each reactive config evaluation; define one
QueryClient before the createFetchQuery/createFetchInfiniteQuery config function
and reference that stable instance inside it. Apply this to
src/preset/create-fetch-query.test.ts:305-308 and
src/preset/create-fetch-infinite-query.test.ts:283-288.
🤖 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.

Outside diff comments:
In `@docs/preset/createFetchInfiniteQuery.md`:
- Line 51: Replace the internal source-file link to mount-query-client-once.ts
in the createFetchInfiniteQuery documentation with a stable documentation URL or
repository source URL that resolves correctly in the published site.

---

Nitpick comments:
In `@src/preset/create-fetch-query.test.ts`:
- Around line 305-308: Both refetch tests create a new QueryClient on each
reactive config evaluation; define one QueryClient before the
createFetchQuery/createFetchInfiniteQuery config function and reference that
stable instance inside it. Apply this to
src/preset/create-fetch-query.test.ts:305-308 and
src/preset/create-fetch-infinite-query.test.ts:283-288.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 19f62082-5937-4145-9869-e3644831086f

📥 Commits

Reviewing files that changed from the base of the PR and between 91ac7db and ef6feeb.

📒 Files selected for processing (18)
  • docs/api/FetchInfiniteQuery.md
  • docs/api/FetchQuery.md
  • docs/api/QueryClient.md
  • docs/errors/2.md
  • docs/preset/createFetchInfiniteQuery.md
  • docs/preset/createFetchQuery.md
  • src/fetch-infinite-query.test.ts
  • src/fetch-infinite-query.ts
  • src/fetch-query.test.ts
  • src/fetch-query.ts
  • src/preset/create-fetch-infinite-query.test.ts
  • src/preset/create-fetch-infinite-query.ts
  • src/preset/create-fetch-query.test.ts
  • src/preset/create-fetch-query.ts
  • src/preset/create-infinite-query.ts
  • src/preset/create-query-instance.ts
  • src/preset/create-query.ts
  • src/utils/make-fetch-request.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • docs/api/QueryClient.md
  • docs/api/FetchInfiniteQuery.md
  • docs/preset/createFetchQuery.md
  • docs/errors/2.md
  • docs/api/FetchQuery.md
  • src/fetch-query.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 18 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/fetch-infinite-query.ts">

<violation number="1" location="src/fetch-infinite-query.ts:359">
P2: A page fetch can send stale request parameters after reactive `params` disables the query, because a falsy fresh result falls back to the previous key's params. Handle a falsy callback result as unconfigured instead of issuing the cached request.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

: undefined;

const fetchParams: FetchInfiniteQueryParams<TOutputData, TPageParam> = {
...(freshParams || baseFetchParams),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: A page fetch can send stale request parameters after reactive params disables the query, because a falsy fresh result falls back to the previous key's params. Handle a falsy callback result as unconfigured instead of issuing the cached request.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/fetch-infinite-query.ts, line 359:

<comment>A page fetch can send stale request parameters after reactive `params` disables the query, because a falsy fresh result falls back to the previous key's params. Handle a falsy callback result as unconfigured instead of issuing the cached request.</comment>

<file context>
@@ -292,14 +348,22 @@ export class FetchInfiniteQuery<
+
         const fetchParams: FetchInfiniteQueryParams<TOutputData, TPageParam> = {
-          ...baseFetchParams,
+          ...(freshParams || baseFetchParams),
           pageParam: pageParam as TPageParam,
         };
</file context>

@coderabbitai coderabbitai Bot mentioned this pull request Aug 11, 2026
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