@raf-query/react 0.0.4 → 0.0.6
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 +13 -1
- package/dist/hydrate.mjs +43 -12
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.6](https://github.com/KATT/raf-query/compare/0.0.5...0.0.6) (2026-10-12)
|
|
4
|
+
|
|
5
|
+
* experimental @raf-query/tanstack-react-query on TanStack Query ([#8](https://github.com/KATT/raf-query/issues/8)) ([9d909c4](https://github.com/KATT/raf-query/commit/9d909c46ca030fd465d7af0fcd9591818356dd80))
|
|
6
|
+
|
|
7
|
+
## [0.0.5](https://github.com/KATT/raf-query/compare/0.0.4...0.0.5) (2026-10-12)
|
|
8
|
+
|
|
9
|
+
- **examples:** use Zod instead of Effect Schema ([#6](https://github.com/KATT/raf-query/issues/6)) ([7068cbe](https://github.com/KATT/raf-query/commit/7068cbe95e693787f22908b0ed678f6b7b05a550))
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
- **react:** HydrationBoundary defers newer data for entries already on screen ([#5](https://github.com/KATT/raf-query/issues/5)) ([881a535](https://github.com/KATT/raf-query/commit/881a53544f65e2ffe858a0d010d7109427b93d55))
|
|
14
|
+
|
|
3
15
|
## [0.0.4](https://github.com/KATT/raf-query/compare/0.0.3...0.0.4) (2026-10-12)
|
|
4
16
|
|
|
5
17
|
### Features
|
|
6
18
|
|
|
7
|
-
|
|
19
|
+
- @raf-query/core, @raf-query/react and the example apps ([#1](https://github.com/KATT/raf-query/issues/1)) ([3881014](https://github.com/KATT/raf-query/commit/3881014b7f07d17d733256e184b627ead1f5788b))
|
|
8
20
|
|
|
9
21
|
## [0.0.3](https://github.com/KATT/raf-query/compare/0.0.2...0.0.3) (2026-10-12)
|
|
10
22
|
|
package/dist/hydrate.mjs
CHANGED
|
@@ -1,32 +1,63 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useQueryClient } from "./provider.mjs";
|
|
3
3
|
import { hashKey, hydrate } from "@raf-query/core";
|
|
4
|
-
import { useState } from "react";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
5
|
//#region src/hydrate.tsx
|
|
6
6
|
const hydratedByClient = /* @__PURE__ */ new WeakMap();
|
|
7
7
|
/** Hashes of entries a client received through {@link Hydrate}. */
|
|
8
8
|
function hydratedHashes(client) {
|
|
9
9
|
return hydratedByClient.get(client) ?? /* @__PURE__ */ new Set();
|
|
10
10
|
}
|
|
11
|
+
function markHydrated(client, state) {
|
|
12
|
+
let hashes = hydratedByClient.get(client);
|
|
13
|
+
if (!hashes) {
|
|
14
|
+
hashes = /* @__PURE__ */ new Set();
|
|
15
|
+
hydratedByClient.set(client, hashes);
|
|
16
|
+
}
|
|
17
|
+
for (const query of state.queries) hashes.add(hashKey(query.key));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Entries the client has no data for, which children need during this
|
|
21
|
+
* render, and entries it already shows, which must wait for a commit.
|
|
22
|
+
*/
|
|
23
|
+
function split(client, state) {
|
|
24
|
+
const shown = new Set(client.getAll().filter((query) => query.getState().hasData).map((query) => query.hash));
|
|
25
|
+
const isShown = (query) => shown.has(hashKey(query.key));
|
|
26
|
+
return {
|
|
27
|
+
deferred: { queries: state.queries.filter(isShown) },
|
|
28
|
+
now: { queries: state.queries.filter((query) => !isShown(query)) }
|
|
29
|
+
};
|
|
30
|
+
}
|
|
11
31
|
/**
|
|
12
|
-
* Writes dehydrated entries into the provided client
|
|
13
|
-
*
|
|
32
|
+
* Writes dehydrated entries into the provided client. Entries the client has
|
|
33
|
+
* no data for are written before its children render, so their reads find
|
|
34
|
+
* the data (or the server's pending request). Newer data for entries already
|
|
35
|
+
* on screen is written after commit, so a render React throws away (an
|
|
36
|
+
* interrupted navigation) doesn't change the current page.
|
|
14
37
|
* Rendered by `HydrationBoundary`; apps don't use it directly.
|
|
15
38
|
*/
|
|
16
39
|
function Hydrate(props) {
|
|
17
40
|
const client = useQueryClient();
|
|
18
41
|
const state = props.state;
|
|
42
|
+
const options = props.options;
|
|
19
43
|
const [hydrated, setHydrated] = useState();
|
|
20
|
-
if (hydrated !== state) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
setHydrated(state);
|
|
44
|
+
if (hydrated?.state !== state) {
|
|
45
|
+
const parts = split(client, state);
|
|
46
|
+
markHydrated(client, state);
|
|
47
|
+
hydrate(client, parts.now, options);
|
|
48
|
+
setHydrated({
|
|
49
|
+
deferred: parts.deferred,
|
|
50
|
+
state
|
|
51
|
+
});
|
|
29
52
|
}
|
|
53
|
+
const deferred = hydrated?.deferred;
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (deferred && deferred.queries.length > 0) hydrate(client, deferred, options);
|
|
56
|
+
}, [
|
|
57
|
+
client,
|
|
58
|
+
deferred,
|
|
59
|
+
options
|
|
60
|
+
]);
|
|
30
61
|
return props.children;
|
|
31
62
|
}
|
|
32
63
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raf-query/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "React bindings for raf-query, a render-as-you-fetch query library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"query",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"./tanstack-router": "./dist/tanstack-router.mjs"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@raf-query/core": "0.0.
|
|
41
|
+
"@raf-query/core": "0.0.6",
|
|
42
42
|
"effect": "^4.0.1"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|