@smithers-orchestrator/gateway-react 0.18.0 → 0.19.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithers-orchestrator/gateway-react",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "React hooks and root helpers for Smithers Gateway UIs",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -20,8 +20,8 @@
20
20
  "src/"
21
21
  ],
22
22
  "dependencies": {
23
- "@smithers-orchestrator/gateway": "0.18.0",
24
- "@smithers-orchestrator/gateway-client": "0.18.0"
23
+ "@smithers-orchestrator/gateway": "0.19.0",
24
+ "@smithers-orchestrator/gateway-client": "0.19.0"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "react": "^19.0.0",
@@ -8,8 +8,13 @@ export function useGatewayActions() {
8
8
  launchRun: client.launchRun.bind(client),
9
9
  resumeRun: client.resumeRun.bind(client),
10
10
  cancelRun: client.cancelRun.bind(client),
11
+ hijackRun: client.hijackRun.bind(client),
12
+ rewindRun: client.rewindRun.bind(client),
11
13
  submitApproval: client.submitApproval.bind(client),
12
14
  submitSignal: client.submitSignal.bind(client),
15
+ cronCreate: client.cronCreate.bind(client),
16
+ cronDelete: client.cronDelete.bind(client),
17
+ cronRun: client.cronRun.bind(client),
13
18
  }),
14
19
  [client],
15
20
  );
@@ -1,4 +1,4 @@
1
- import { useCallback, useEffect, useMemo, useState } from "react";
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2
2
  import type { GatewayRpcMethod } from "@smithers-orchestrator/gateway/rpc";
3
3
  import type { GatewayRpcParams, GatewayRpcPayload } from "@smithers-orchestrator/gateway-client";
4
4
  import { useSmithersGateway } from "./useSmithersGateway.ts";
@@ -13,6 +13,14 @@ export function useGatewayRpc<Method extends GatewayRpcMethod>(
13
13
  const enabled = options.enabled ?? true;
14
14
  const paramsKey = useMemo(() => JSON.stringify(params ?? {}), [params]);
15
15
  const deps = options.deps ?? [paramsKey];
16
+ const paramsRef = useRef(params);
17
+ const previousEffectRef = useRef<{
18
+ client: typeof client;
19
+ enabled: boolean;
20
+ method: Method;
21
+ deps: readonly unknown[];
22
+ } | undefined>(undefined);
23
+ paramsRef.current = params;
16
24
  const [data, setData] = useState<GatewayRpcPayload<Method>>();
17
25
  const [error, setError] = useState<Error>();
18
26
  const [loading, setLoading] = useState(enabled);
@@ -24,17 +32,27 @@ export function useGatewayRpc<Method extends GatewayRpcMethod>(
24
32
  setLoading(true);
25
33
  setError(undefined);
26
34
  try {
27
- setData(await client.rpc(method, params));
35
+ setData(await client.rpc(method, paramsRef.current));
28
36
  } catch (cause) {
29
37
  setError(cause instanceof Error ? cause : new Error(String(cause)));
30
38
  } finally {
31
39
  setLoading(false);
32
40
  }
33
- }, [client, enabled, method, paramsKey]);
41
+ }, [client, enabled, method]);
34
42
 
35
43
  useEffect(() => {
36
- void refetch();
37
- }, [refetch, ...deps]);
44
+ const previous = previousEffectRef.current;
45
+ const changed = !previous ||
46
+ previous.client !== client ||
47
+ previous.enabled !== enabled ||
48
+ previous.method !== method ||
49
+ previous.deps.length !== deps.length ||
50
+ deps.some((dep, index) => !Object.is(dep, previous.deps[index]));
51
+ previousEffectRef.current = { client, enabled, method, deps: [...deps] };
52
+ if (changed) {
53
+ void refetch();
54
+ }
55
+ });
38
56
 
39
57
  return { data, error, loading, refetch };
40
58
  }