Skip to content
Source
Sign inSign up
TanStack/db

fix(query-db-collection): cancel idle on-demand queries #1573

Closedsuperposition(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/1573/headopened

Showing 4 changed files with 56 additions and 5 deletions (loading 1).

x
0 of 4 viewed, 4 left
5 additions and 0 deletions.changeset/query-collection-cancel-idle.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/query-db-collection': patch
+---
+​
+Cancel idle on-demand query collection requests during cleanup.
21 additions and 0 deletionsdocs/collections/query-collection.mdModified
View file
@@ -64,6 +64,27 @@
- `staleTime`: How long data is considered fresh
- `meta`: Optional metadata that will be passed to the query function context
​
+### Query Function Context
+​
+`queryFn` receives TanStack Query's `QueryFunctionContext`, including `signal` and `meta`. Query Collections cancel idle on-demand requests during cleanup, so pass `ctx.signal` to abortable request clients:
+​
+```typescript
+const todosCollection = createCollection(
+ queryCollectionOptions({
+ queryKey: ["todos"],
+ syncMode: "on-demand",
+ queryFn: async (ctx) => {
+ const response = await fetch("/api/todos", {
+ signal: ctx.signal,
+ })