You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Note:**`forget` only removes items from the items cache -- it does not cancel pending resolvers. Use `abort` to cancel in-flight requests. If a cached promise has rejected, `forget` handles it gracefully (emits `'forgotten'` with `undefined`).
98
+
99
99
### Hydrate (pre-populate cache)
100
100
101
101
```typescript
@@ -112,12 +112,14 @@ query.abort() // Abort all pending
112
112
query.abort('/api/user', 'cancelled') // With custom reason
113
113
```
114
114
115
+
**Note:** When `fresh: true` is used, `abort(key)` is called before `refetch(key)` to ensure a genuinely new fetch starts instead of returning the pending deduplication promise.
116
+
115
117
### Inspect cache
116
118
117
119
```typescript
118
120
const value =awaitquery.snapshot<User>('/api/user') // Current cached value or undefined
**Note:**`subscribeBroadcast()` captures the broadcast reference at call time. If `configure()` later replaces the channel, the unsubscriber still targets the original. `emit()` wraps `postMessage` in try-catch for non-cloneable data.
174
+
169
175
## React Bindings
170
176
171
-
Designed for React 19+ with first-class Suspense and Transitions support.
177
+
Designed for React 19+ with first-class Suspense and Transitions support. Uses React Compiler for automatic memoization -- do NOT use `useMemo`, `useCallback`, or `React.memo`.
172
178
173
179
### Setup
174
180
@@ -194,7 +200,7 @@ function App() {
194
200
-`clearOnForget?` - Auto-refetch after `forget()` (default `false`)
195
201
-`ignoreTransitionContext?` - Use local transitions instead of shared (default `false`)
`QueryProvider` automatically handles BroadcastChannel setup, cleanup, and cross-tab event forwarding. Includes a guard for environments where `BroadcastChannel` is unavailable.
@@ -348,12 +354,18 @@ Pattern: create query with mock fetcher, pass it via `{ query }` option to bypas
348
354
349
355
-**Expiration is a function, not a number.** Always `expiration: () => 5000`, not `expiration: 5000`.
350
356
-**`useQuery` suspends.** Components must be inside `<Suspense>` or React throws.
351
-
-**`data` from `useQuery` is always resolved.**It's never undefined or null from a loading state. Suspense handles loading.
357
+
-**`data` from `useQuery` is always resolved.**Never undefined/null from loading state. Suspense handles loading.
352
358
-**`hydrate` without expiration creates immediately-stale data.** The first `query()` returns the hydrated value, the second triggers a refetch.
353
-
-**Mutation with `expiration: () => 0` makes the value immediately stale.** Provide a non-zero expiration in `mutate` options if you want it to persist.
354
-
-**`forget` does not cancel pending fetches.** Use `abort` to cancel in-flight requests.
359
+
-**Mutation with `expiration: () => 0` makes the value immediately stale.** Provide a non-zero expiration if you want it to persist.
360
+
-**`forget` does not cancel pending fetches.**Only removes items from the items cache. Use `abort` to cancel in-flight requests.
355
361
-**`stale: false` blocks until refetch completes.** Default `stale: true` returns old data while revalidating in the background.
356
-
-**`subscribe('refetching')` on a key with a pending resolver fires immediately.**This is intentional for late subscribers.
362
+
-**`subscribe('refetching')` on a key with a pending resolver fires immediately.**Intentional for late subscribers.
357
363
-**BroadcastChannel is not auto-created in vanilla usage.**`QueryProvider` handles it in React. In core, configure it manually.
358
364
-**Pass stable `keys` arrays to `useQueryPrefetch` / `QueryPrefetch`.** Use `useMemo` or a module-level constant to avoid infinite re-renders.
359
365
-**`useQueryInstance` throws if no query is in context or options.** Ensure `QueryProvider` is an ancestor or pass `{ query }` in options.
366
+
-**React Compiler handles memoization.** Do NOT use `useMemo`, `useCallback`, or `React.memo` -- the compiler does it automatically.
367
+
-**`once()` and `next()` accept an optional `AbortSignal`.** Use to cancel pending listeners when breaking out of generators.
368
+
-**`stream()` and `sequence()` clean up on break.** Internal `AbortController` cancels pending listeners via `finally` block.
369
+
-**Abort race condition is handled.** If `abort()` fires after fetch resolves but before cache write, the result is discarded and the promise rejects.
370
+
-**`next()` supports object keys.**`await query.next<{ user: User }>({ user: '/api/user' })` returns an object with the same shape.
371
+
-**`fresh: true` aborts then refetches.** Ensures a genuinely new fetch instead of returning the pending deduplication promise.
0 commit comments