FetchQueries and FetchInfiniteQueries - #89
Conversation
📝 WalkthroughWalkthroughAdds reactive ChangesFetch query support
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
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 12
🧹 Nitpick comments (3)
src/preset/create-fetch-query.ts (1)
31-50: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider extracting shared factory logic to reduce duplication.
The implementation of
createFetchQuery(lines 31-50) is nearly identical tocreateFetchInfiniteQuery(lines 80-99) — same args-length dispatch, same function-vs-object wrapping, samemountQueryClientOnce(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 valueMinor 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 calldestroy(). 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 valueMinor 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 calldestroy(). They are functionally identical. Consider consolidating or differentiating the second test to verify the preset client is actually used (e.g., by checkingquery.options.queryClientor 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
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (29)
.changeset/wet-turtles-relax.md.github/workflows/version-or-publish.ymldocs/.vitepress/config.mtsdocs/api/FetchInfiniteQuery.mddocs/api/FetchQuery.mddocs/api/QueryClient.mddocs/api/other.mddocs/errors/1.mddocs/errors/2.mddocs/preset/createFetchInfiniteQuery.mddocs/preset/createFetchQuery.mddocs/preset/index.mdpackage.jsonscripts/prepare-dist.tssrc/fetch-infinite-query.tssrc/fetch-query.test.tssrc/fetch-query.tssrc/index.tssrc/inifinite-query.types.tssrc/preset/create-fetch-infinite-query.test.tssrc/preset/create-fetch-infinite-query.tssrc/preset/create-fetch-query.test.tssrc/preset/create-fetch-query.tssrc/preset/index.tssrc/query-client.tssrc/query-client.types.tssrc/utils/make-fetch-request.tstsconfig.jsontsconfig.test.json
There was a problem hiding this comment.
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
There was a problem hiding this comment.
All reported issues were addressed across 5 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (4)
docs/api/FetchQuery.md (2)
28-56: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winInitialize the MobX box with a value.
observable.box<string>()needs an initial value — useobservable.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 winUse complete
Recordtype arguments.Record<string>on line 93 is invalid TypeScript; document headers asRecord<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
FetchInfiniteQueryPositionalConfigstill omits pagination options.This interface omits
initialPageParam,getNextPageParam, andgetPreviousPageParam(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 winType inconsistency between
TOutputDataandTQueryFnDatapersists.
select(line 85) and pagination callbacks (lines 70–75) useTQueryFnData, butqueryFn(line 300) returnsTOutputData | nullfrommakeFetchRequest<TOutputData>. When callers specify differentTQueryFnDataandTOutputDatagenerics, 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
📒 Files selected for processing (7)
docs/api/FetchInfiniteQuery.mddocs/api/FetchQuery.mdpackage.jsonsrc/fetch-infinite-query.tssrc/fetch-query.tssrc/preset/create-fetch-query.test.tssrc/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
There was a problem hiding this comment.
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 winReplace 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 winBoth refetch tests allocate the
QueryClientinside the reactive config function. The config function re-runs when the observable changes, so each evaluation returns a newQueryClient. A per-evaluation client defeats the query cache, andmountQueryClientOncemounts 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 theQueryClientonce 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
📒 Files selected for processing (18)
docs/api/FetchInfiniteQuery.mddocs/api/FetchQuery.mddocs/api/QueryClient.mddocs/errors/2.mddocs/preset/createFetchInfiniteQuery.mddocs/preset/createFetchQuery.mdsrc/fetch-infinite-query.test.tssrc/fetch-infinite-query.tssrc/fetch-query.test.tssrc/fetch-query.tssrc/preset/create-fetch-infinite-query.test.tssrc/preset/create-fetch-infinite-query.tssrc/preset/create-fetch-query.test.tssrc/preset/create-fetch-query.tssrc/preset/create-infinite-query.tssrc/preset/create-query-instance.tssrc/preset/create-query.tssrc/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
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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>
Summary by cubic
Add
FetchQueryandFetchInfiniteQueryfor first-class HTTP queries with MobX reactivity and simple params. Also adds presets and globalQueryClient.fetchQueriesdefaults, with docs, types, and tests.New Features
FetchQuery/FetchInfiniteQuerywith declarativeparams, function-based configs that track MobX observables, andstart({ params }).queryKey;makeFetchRequestbuilds URLs, merges headers, handles JSON/native bodies, 404→null,responseType, abort/timeout, credentials/mode, and per-client defaults.QueryClient.fetchQueries(baseUrl, headers,customFetch,transformResponse,throwOnError, timeout, credentials, mode, meta); presetscreateFetchQuery/createFetchInfiniteQueryauto-mount the client and accept options or a function; new API/preset pages and error guides (How to define the type ofMeta#1, [Feature Request] AddqueryOptionsfunction #2), plus inference/config-from-fn types and exports.Bug Fixes
Written for commit ef6feeb. Summary will update on new commits.
Summary by CodeRabbit
New Features
Documentation