@raf-query/react 0.0.4 → 0.0.5

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 CHANGED
@@ -1,10 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.5](https://github.com/KATT/raf-query/compare/0.0.4...0.0.5) (2026-10-12)
4
+
5
+ * **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))
6
+
7
+ ### Bug Fixes
8
+
9
+ * **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))
10
+
3
11
  ## [0.0.4](https://github.com/KATT/raf-query/compare/0.0.3...0.0.4) (2026-10-12)
4
12
 
5
13
  ### Features
6
14
 
7
- * @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))
15
+ - @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
16
 
9
17
  ## [0.0.3](https://github.com/KATT/raf-query/compare/0.0.2...0.0.3) (2026-10-12)
10
18
 
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 before its children
13
- * render, so their reads find the data (or the server's pending request).
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
- let hashes = hydratedByClient.get(client);
22
- if (!hashes) {
23
- hashes = /* @__PURE__ */ new Set();
24
- hydratedByClient.set(client, hashes);
25
- }
26
- for (const query of state.queries) hashes.add(hashKey(query.key));
27
- hydrate(client, state, props.options);
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.4",
3
+ "version": "0.0.5",
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.4",
41
+ "@raf-query/core": "0.0.5",
42
42
  "effect": "^4.0.1"
43
43
  },
44
44
  "peerDependencies": {