@shivaedev/react 0.46.5 → 0.46.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.46.6 - 2026-11-08
4
+
5
+ ### Fixed
6
+
7
+ - `usePendingCommand` keeps the requested value after a successful command until a watched query delivers its next settled Result, so a switch backed by a live query no longer flips back to the old value before the server's push arrives.
8
+
3
9
  ## 0.46.5 - 2026-11-07
4
10
 
5
11
  ### Changed
package/README.md CHANGED
@@ -650,7 +650,7 @@ Each row needs its own action atom because the native atom owns its current resu
650
650
 
651
651
  The example assumes a bound `api.toggle.run` accepting `{ id, enabled }`, a bound list query and their native `ItemsClient`. `queries` lists the query atoms whose next results the display waits for; it does not add invalidations. Include every relevant query and keep the action and query atom identities stable. `value` is the current server value; `wanted(input)` computes the requested display value.
652
652
 
653
- `command.value` changes on dispatch and stays at the requested value while the command or any watched query is waiting. `pending` covers that whole interval. After the queries settle, `value` follows the server again, even if it differs from the requested value. A command failure immediately returns to the server value and remains typed in `result` and `cause`, just as with `useAction`. The other action fields describe the native command result, so `result` can already be successful while `pending` still waits for refetches. This binding holds a display value; it does not write to the query cache.
653
+ `command.value` changes on dispatch and holds the requested value until the command has succeeded, no watched query is waiting, and at least one watched query has delivered a settled Result it did not have at dispatch. A reload and a live query's pushed Result both count, so a live switch does not fall back to the old server value between the command's response and the push. `pending` covers that whole interval. After the hold ends, `value` follows the server again, even if it differs from the requested value. A command failure immediately returns to the server value and remains typed in `result` and `cause`, just as with `useAction`. The other action fields describe the native command result, so `result` can already be successful while `pending` still waits for refetches. This binding holds a display value; it does not write to the query cache.
654
654
 
655
655
  #### Trace an action across RPCs
656
656
 
@@ -1 +1 @@
1
- {"version":3,"file":"pendingCommand.d.ts","sourceRoot":"","sources":["../../src/client/pendingCommand.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,WAAW,MAAM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WAAW,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;IAClF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C;AACD,MAAM,WAAW,mBAAmB,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,CAAE,SAAQ,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;IAC3F,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EACrD,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,EACrC,OAAO,EAAE,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5C,mBAAmB,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAyB3C"}
@@ -8,19 +8,22 @@ export function usePendingCommand(atom, options) {
8
8
  const action = useAction(atom);
9
9
  const registry = useContext(RegistryContext);
10
10
  const { queries, value, wanted } = options;
11
- const waiting = useMemo(() => Atom.make((get) => queries.map((query) => get(query).waiting).some(Boolean)), [queries]);
12
- const refreshing = useAtomValue(waiting);
13
- const [held, hold] = useState({ atom, registry, value: Option.none() });
11
+ const watched = useMemo(() => Atom.make((get) => queries.map((query) => get(query))), [queries]);
12
+ const results = useAtomValue(watched);
13
+ const [held, hold] = useState({ atom, before: results, registry, value: Option.none() });
14
14
  const sameOwner = held.atom === atom && held.registry === registry;
15
15
  const failed = AsyncResult.isFailure(action.result) && !action.pending;
16
- const pending = sameOwner && Option.isSome(held.value) && !failed && (action.pending || refreshing);
16
+ const refreshing = results.some((result) => result.waiting);
17
+ // A live query answers with a pushed Result instead of a reload, so the hold waits for any new settled Result.
18
+ const answered = results.some((result, index) => !result.waiting && result !== held.before[index]);
19
+ const pending = sameOwner && Option.isSome(held.value) && !failed && (action.pending || refreshing || !answered);
17
20
  if (!sameOwner || (Option.isSome(held.value) && !pending)) {
18
- hold({ atom, registry, value: Option.none() });
21
+ hold({ atom, before: results, registry, value: Option.none() });
19
22
  }
20
23
  return {
21
24
  ...action,
22
25
  dispatch: (input) => {
23
- hold({ atom, registry, value: Option.some(wanted(input)) });
26
+ hold({ atom, before: registry.get(watched), registry, value: Option.some(wanted(input)) });
24
27
  action.dispatch(input);
25
28
  },
26
29
  pending: action.pending || pending,
@@ -1 +1 @@
1
- {"version":3,"file":"pendingCommand.js","sourceRoot":"","sources":["../../src/client/pendingCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAoB,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAWrE,MAAM,UAAU,iBAAiB,CAChC,IAAqC,EACrC,OAA8C;IAE9C,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,QAAQ,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAC7C,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3C,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,C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CAAC,CAAC;QACxB,CAAC;QACD,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,OAAO;QAClC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK;KAClE,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/react",
3
- "version": "0.46.5",
3
+ "version": "0.46.6",
4
4
  "description": "React query, action, editor and session hooks for native Effect atoms",
5
5
  "keywords": [
6
6
  "effect"
@@ -59,7 +59,7 @@
59
59
  "@shivaedev/changes": "0.11.1",
60
60
  "@shivaedev/jobs": "0.41.4",
61
61
  "@shivaedev/quality": "0.74.0",
62
- "@shivaedev/server": "0.33.0",
62
+ "@shivaedev/server": "0.33.1",
63
63
  "@shivaedev/service": "0.8.2",
64
64
  "@shivaedev/sql": "0.46.3",
65
65
  "@shivaedev/test-kits": "0.10.6",
@@ -21,19 +21,22 @@ export function usePendingCommand<TInput, A, E, TValue>(
21
21
  const action = useAction(atom);
22
22
  const registry = useContext(RegistryContext);
23
23
  const { queries, value, wanted } = options;
24
- const waiting = useMemo(() => Atom.make((get) => queries.map((query) => get(query).waiting).some(Boolean)), [queries]);
25
- const refreshing = useAtomValue(waiting);
26
- const [held, hold] = useState({ atom, registry, value: Option.none<TValue>() });
24
+ const watched = useMemo(() => Atom.make((get) => queries.map((query) => get(query))), [queries]);
25
+ const results = useAtomValue(watched);
26
+ const [held, hold] = useState({ atom, before: results, registry, value: Option.none<TValue>() });
27
27
  const sameOwner = held.atom === atom && held.registry === registry;
28
28
  const failed = AsyncResult.isFailure(action.result) && !action.pending;
29
- const pending = sameOwner && Option.isSome(held.value) && !failed && (action.pending || refreshing);
29
+ const refreshing = results.some((result) => result.waiting);
30
+ // A live query answers with a pushed Result instead of a reload, so the hold waits for any new settled Result.
31
+ const answered = results.some((result, index) => !result.waiting && result !== held.before[index]);
32
+ const pending = sameOwner && Option.isSome(held.value) && !failed && (action.pending || refreshing || !answered);
30
33
  if (!sameOwner || (Option.isSome(held.value) && !pending)) {
31
- hold({ atom, registry, value: Option.none() });
34
+ hold({ atom, before: results, registry, value: Option.none() });
32
35
  }
33
36
  return {
34
37
  ...action,
35
38
  dispatch: (input) => {
36
- hold({ atom, registry, value: Option.some(wanted(input)) });
39
+ hold({ atom, before: registry.get(watched), registry, value: Option.some(wanted(input)) });
37
40
  action.dispatch(input);
38
41
  },
39
42
  pending: action.pending || pending,