@raf-query/core 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -2
- package/README.md +8 -17
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.4.1](https://github.com/KATT/raf-query/compare/0.4.0...0.4.1) (2026-10-13)
|
|
4
|
+
|
|
5
|
+
* one table for the query verbs; fetch and ensure wait alike in server components ([#64](https://github.com/KATT/raf-query/issues/64)) ([13e5549](https://github.com/KATT/raf-query/commit/13e5549e9f1b6df4fe0e8f23f79e1aef7bf94e53))
|
|
6
|
+
|
|
3
7
|
## [0.4.0](https://github.com/KATT/raf-query/compare/0.3.1...0.4.0) (2026-10-13)
|
|
4
8
|
|
|
5
9
|
### ⚠ BREAKING CHANGES
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
- **core:** fetch waits for stale data, as TanStack's fetchQuery does ([#63](https://github.com/KATT/raf-query/issues/63))
|
|
8
12
|
|
|
9
13
|
### Bug Fixes
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
- **core:** fetch waits for stale data, as TanStack's fetchQuery does ([#63](https://github.com/KATT/raf-query/issues/63)) ([c9785d5](https://github.com/KATT/raf-query/commit/c9785d5e99c0578c1748de3330823cc0e65f2378))
|
|
12
16
|
|
|
13
17
|
## [0.3.1](https://github.com/KATT/raf-query/compare/0.3.0...0.3.1) (2026-10-13)
|
|
14
18
|
|
package/README.md
CHANGED
|
@@ -118,23 +118,15 @@ declare module "@raf-query/react" {
|
|
|
118
118
|
|
|
119
119
|
## Starting queries
|
|
120
120
|
|
|
121
|
-
All three verbs live on the query client and accept a factory plus its input.
|
|
121
|
+
All three verbs live on the query client and accept a factory plus its input. They differ in what they return and what they wait for:
|
|
122
122
|
|
|
123
|
-
| Call
|
|
124
|
-
|
|
|
125
|
-
| `qc.prefetch(factory, input)`
|
|
126
|
-
| `
|
|
127
|
-
| `
|
|
123
|
+
| Call | Returns | Cache miss | Stale data | TanStack Query |
|
|
124
|
+
| ----------------------------- | ----------------------------- | --------------------- | --------------------------------------------- | ---------------------------------------------- |
|
|
125
|
+
| `qc.prefetch(factory, input)` | `QueryHandle` | Starts the request | Refetches in the background | `prefetchQuery`, not awaited |
|
|
126
|
+
| `qc.ensure(factory, input)` | `Promise<EnsuredQueryHandle>` | Waits for the request | Resolves at once, refetches in the background | `ensureQueryData({ revalidateIfStale: true })` |
|
|
127
|
+
| `qc.fetch(factory, input)` | `Promise<Data>` | Waits for the request | Waits for the refetch | `fetchQuery` |
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
| Verb | Cache miss | Stale data | Fresh data | TanStack Query |
|
|
132
|
-
| ---------- | --------------------- | --------------------------------------------- | ---------------- | ---------------------------------------------- |
|
|
133
|
-
| `prefetch` | Starts the request | Refetches in the background | Reused | `prefetchQuery`, not awaited |
|
|
134
|
-
| `ensure` | Waits for the request | Resolves at once, refetches in the background | Resolves at once | `ensureQueryData({ revalidateIfStale: true })` |
|
|
135
|
-
| `fetch` | Waits for the request | Waits for the refetch | Resolves at once | `fetchQuery` |
|
|
136
|
-
|
|
137
|
-
So `prefetch` never holds anything up, `ensure` holds up only the first visit (returning to a page shows the cached data at once, then fresh data), and `fetch` always returns fresh data, at the cost of a round trip whenever the cache is stale. On the server, data counts as stale only once `invalidate` has marked it (see below).
|
|
129
|
+
Fresh cached data is reused by all three, without a request. So `prefetch` never holds anything up, `ensure` holds up only the first visit (returning to a page shows the cached data at once, then fresh data), and `fetch` always returns fresh data, at the cost of a round trip whenever the cache is stale. On the server, data counts as stale only once `invalidate` has marked it (see below).
|
|
138
130
|
|
|
139
131
|
```tsx
|
|
140
132
|
// TanStack Start
|
|
@@ -650,8 +642,7 @@ export default async function Page(props: {
|
|
|
650
642
|
- `HydrationBoundary` sends the request client's entries to the browser cache; pending ones stream as promises through the RSC payload. Render one in each server component that starts queries for client components. Entries already sent in this request are skipped.
|
|
651
643
|
- The browser takes whichever copy is newer, by when it was fetched (`updatedAt`, so server and browser clocks should agree). When it has no data and no request of its own, it resumes the server's pending request. When it has data, or its own request in flight, it waits for the server's instead of fetching again, and takes it if newer. If it keeps its own copy (the server's is older, as in a payload the router replays from its cache on back and forward, or the server's request failed), it refetches it if stale.
|
|
652
644
|
- `QueryProvider` creates one client per server render and one per browser tab. The server render starts no request: a client component reading a query no `HydrationBoundary` sent renders its Suspense fallback on the server, and the query loads in the browser. That boundary renders in the browser through React's error recovery, with the digest Next.js uses for `ssr: false`, so Next.js doesn't report it; other frameworks pass it to `onRecoverableError`. Pass `config` for the client's options; it must be serializable.
|
|
653
|
-
-
|
|
654
|
-
- `fetch` returns data, not a handle. When a server component renders the data and also hands the query to a client component, pass `await qc.ensure(...)`: after the `fetch` it resolves from the cache, and the client component gets the data from `useQuery` without a promise.
|
|
645
|
+
- In a server component, `fetch` and `ensure` wait for the same thing: the per-request client only refetches what `invalidate` marked, so cached data is never stale there, and each query makes one request whatever its `staleTime`. They differ only in what they return. `await qc.fetch(...)` the data the server component renders itself, anywhere in the tree. When it also hands the query to a client component, pass `await qc.ensure(...)`: after the `fetch` it resolves from the cache, and the client component gets the data from `useQuery` without a promise.
|
|
655
646
|
- Factories can call server actions: server components call them directly, and the browser calls them on refetch. Validate their arguments, since anyone can call them. The browser runs a page's server actions one at a time, so refetches wait for each other and for any pending mutation. For parallel requests, have the `queryFn` call a [Route Handler](https://nextjs.org/docs/app/api-reference/file-conventions/route), as [`examples/nextjs`](examples/nextjs) does.
|
|
656
647
|
|
|
657
648
|
#### Server-only queries
|