@shivaedev/react 0.47.3 → 0.48.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/CHANGELOG.md +10 -0
- package/README.md +3 -1
- package/dist/client/actionCompletion.d.ts.map +1 -1
- package/dist/client/actionCompletion.js +2 -0
- package/dist/client/actionCompletion.js.map +1 -1
- package/dist/client/adapters/useFirstSettled.d.ts +3 -0
- package/dist/client/adapters/useFirstSettled.d.ts.map +1 -0
- package/dist/client/adapters/useFirstSettled.js +6 -0
- package/dist/client/adapters/useFirstSettled.js.map +1 -0
- package/dist/client/adapters/useStableRun.d.ts +2 -0
- package/dist/client/adapters/useStableRun.d.ts.map +1 -0
- package/dist/client/adapters/useStableRun.js +20 -0
- package/dist/client/adapters/useStableRun.js.map +1 -0
- package/package.json +10 -10
- package/src/client/actionCompletion.ts +2 -0
- package/src/client/adapters/useFirstSettled.ts +6 -0
- package/src/client/adapters/useStableRun.ts +23 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.48.0 - 2026-11-18
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `useFirstSettled(client)` from `@shivaedev/react/client/adapters/useFirstSettled.ts` tells an application when a session's first screen is ready. It returns `false` until a query mounted on the client has delivered its first success or failure and no mounted query awaits a first result and no command is in flight, then stays `true` for that client through later commands and newly mounted queries. A new session generation whose `connect` makes a new client starts at `false` again, and a client that mounts no query stays at `false`.
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- `useAction(runtime, run)` with a `run` function written inline in the component fails its next render with an error that names `useAction`, says `run` is the action's identity and gives the fix: pass a bound command such as `api.rename.run`, or wrap the function in `useCallback` or `useMemo`. Such a component used to fail with React's `Too many re-renders`. Replacing a mounted control's command with another stable function works as before.
|
|
12
|
+
|
|
3
13
|
## 0.47.3 - 2026-11-11
|
|
4
14
|
|
|
5
15
|
### Changed
|
package/README.md
CHANGED
|
@@ -32,6 +32,8 @@ An **editor** joins a query atom, a form field schema and a save Effect. The que
|
|
|
32
32
|
|
|
33
33
|
Use `useConnectionStatus(client)` from `@shivaedev/react/client/adapters/useConnectionStatus.ts` with the client returned by contract's `makeClient`. It returns one `"live" | "reconnecting" | "waiting-for-connection"` value across mounted queries from every binding on that client's `Client` service. Live subscription status changes debounce for 300 ms on the client runtime's Clock. A bound command held for reconnection reports `"waiting-for-connection"` immediately, so the application can show Reconnecting while keeping the action pending. Contract holds unsent commands for up to 10 seconds and returns a typed `RpcClientError` on timeout; commands already sent are never replayed. The default socket probes Ping/Pong on browser or native resume and reconnects after 2.5 seconds without a Pong. A query refusal is separate from connectivity. Visible browser `online` and `visibilitychange` signals interrupt the live retry delay and reconnect immediately with a fresh backoff schedule.
|
|
34
34
|
|
|
35
|
+
Use `useFirstSettled(client)` from `@shivaedev/react/client/adapters/useFirstSettled.ts` with the same client to reveal a session's first screen in one step instead of one loading state per query. It returns `false` until a query mounted on that client has delivered its first success or failure and, with that, no mounted query awaits a first result and no command is in flight. From then on it returns `true` for that client: a later command or a newly mounted query does not turn it back. The signal belongs to the client, so a new session generation whose `connect` makes a new client starts at `false` again. A client whose screen mounts no query stays at `false`; gate only screens that read through the client.
|
|
36
|
+
|
|
35
37
|
A **session generation** is the string returned by `identify(session)`. `SessionBoundary` owns its client, registry and React subtree. Your auth owner supplies the session and decides when to replace or end it. The boundary automatically mounts live connections on bound contract APIs returned by `connect`, directly or as client properties such as `api`. Use a Platform database host and the default shared WebSocket client; the application needs no subscribe handler or `live()` call. The process holding the socket reloads the session and runs the read policy and handler for each subscriber independently. It stores one encoded-result hash per subscribed query in memory and pushes changed values; equal reads acknowledge completion without replacing the screen. Each subscription has at most one rerun in flight and one pending, merging further changes while busy. Other subscriptions run independently in parallel. Backlog overflow triggers a server `Resync`: the server reruns queries itself, and the client sends no follow-up reads. Query results stay in their native registry; RPC declarations and transport stay with native Effect and the application; this package supplies their React state and lifecycle boundary.
|
|
36
38
|
|
|
37
39
|
An explicit query refresh keeps the current data visible while reporting pending until the new subscription result arrives. Retryable connection failures keep that data visible during reconnection. Render read denials before retained data; replacing or ending the session disposes its registry.
|
|
@@ -562,7 +564,7 @@ const rename = useAction(ReportsClient.runtime, api.rename.run, {
|
|
|
562
564
|
|
|
563
565
|
`ReportsClient` and `api` belong to the application. Input, success, typed failure and runtime requirements are inferred from the command. Use `notices` for the feedback path above. The optional synchronous `onSuccess(value, input)` and `onFailure(error, input)` callbacks are also available for application completion work. They run inside each invocation using the latest committed callbacks and that invocation's input and outcome. Rerendering a result does not replay completion, and an abandoned render cannot replace the committed callback. A callback that throws becomes a native defect; it does not call `onFailure` as a domain rejection.
|
|
564
566
|
|
|
565
|
-
The command's identity is the native action atom, or the `run` function in the runtime overload. Pass a stable bound function such as `api.rename.run`; memoize wrappers with `useCallback` or `useMemo`. Changing the command on a mounted control keeps `pending` true until its outgoing request settles. Its result, data and cause stay with the outgoing command: a refusal or success from Launch never appears on a replacement Resume control. Resume dispatches its own function and input. Completion callbacks for the outgoing runtime command stop when it is replaced; callbacks for the same command still use the latest committed props.
|
|
567
|
+
The command's identity is the native action atom, or the `run` function in the runtime overload. Pass a stable bound function such as `api.rename.run`; memoize wrappers with `useCallback` or `useMemo`. A `run` written inline in the component is a new function on every render: its next render fails with an error that names `useAction`, says `run` must stay the same function and gives this fix, where React alone reports only `Too many re-renders`. Changing the command on a mounted control keeps `pending` true until its outgoing request settles. Its result, data and cause stay with the outgoing command: a refusal or success from Launch never appears on a replacement Resume control. Resume dispatches its own function and input. Completion callbacks for the outgoing runtime command stop when it is replaced; callbacks for the same command still use the latest committed props.
|
|
566
568
|
|
|
567
569
|
The hook calls the supplied Effect once. A bound contract command still owns invalidation, and completion does not wait for server query reruns and their pushed results. Undo payloads, expected versions and presentation text stay in the application.
|
|
568
570
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionCompletion.d.ts","sourceRoot":"","sources":["../../src/client/actionCompletion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAGpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"actionCompletion.d.ts","sourceRoot":"","sources":["../../src/client/actionCompletion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAGpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIzD,MAAM,WAAW,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK;IACrD,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvD,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACvD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,EAC7D,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,aAAa,CAAC,EAC5E,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,EAC1E,OAAO,EAAE,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GACrC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,CA4DjD"}
|
|
@@ -2,10 +2,12 @@ import { RegistryContext } from "@effect/atom-react";
|
|
|
2
2
|
import { Effect } from "effect";
|
|
3
3
|
import { useContext, useInsertionEffect, useMemo, useRef } from "react";
|
|
4
4
|
import { isUnauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
5
|
+
import { useStableRun } from "#client/adapters/useStableRun.ts";
|
|
5
6
|
import { NoticeContext } from "#client/NoticeContext.ts";
|
|
6
7
|
import { useSessionRecheck } from "#client/sessionBoundary.ts";
|
|
7
8
|
import { publishNotice } from "#noticeStore.ts";
|
|
8
9
|
export function useActionSource(source, run, options) {
|
|
10
|
+
useStableRun(run);
|
|
9
11
|
const registry = useContext(RegistryContext);
|
|
10
12
|
const recheck = useSessionRecheck();
|
|
11
13
|
const notices = useContext(NoticeContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionCompletion.js","sourceRoot":"","sources":["../../src/client/actionCompletion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAA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CAAC;QACD,MAAM,IAAI,GAAG,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAC1E,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC3B,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;IACjD,kBAAkB,CAAC,GAAG,EAAE;QACvB,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC;QAC7B,OAAO,GAAG,EAAE;YACX,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,KAAK,CAAC;QAC/B,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACZ,OAAO,KAAK,CAAC,IAAI,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFirstSettled.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/useFirstSettled.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAkB,MAAM,uCAAuC,CAAC;AAE1F,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAE7D"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { useAtomValue } from "@effect/atom-react";
|
|
2
|
+
import { clientActivity } from "@shivaedev/contract/clientActivity.ts";
|
|
3
|
+
export function useFirstSettled(client) {
|
|
4
|
+
return useAtomValue(clientActivity(client).firstSettled);
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=useFirstSettled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFirstSettled.js","sourceRoot":"","sources":["../../../src/client/adapters/useFirstSettled.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAqB,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAE1F,MAAM,UAAU,eAAe,CAAC,MAAoB;IACnD,OAAO,YAAY,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStableRun.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/useStableRun.ts"],"names":[],"mappings":"AAKA,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,QAiBxC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useInsertionEffect, useRef, useState } from "react";
|
|
2
|
+
// A deliberate swap changes `run` once and commits; React itself stops a component after 25 uncommitted renders without naming the hook.
|
|
3
|
+
const UNCOMMITTED_CHANGES = 10;
|
|
4
|
+
export function useStableRun(run) {
|
|
5
|
+
// State, unlike a ref, is discarded with an abandoned render, so only renders React repeats before one commit are counted.
|
|
6
|
+
const [seen, see] = useState({ changes: 0, run });
|
|
7
|
+
const committedRef = useRef(seen);
|
|
8
|
+
useInsertionEffect(() => {
|
|
9
|
+
committedRef.current = seen;
|
|
10
|
+
}, [seen]);
|
|
11
|
+
if (seen.run === run) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const changes = seen === committedRef.current ? 1 : seen.changes + 1;
|
|
15
|
+
if (changes === UNCOMMITTED_CHANGES) {
|
|
16
|
+
throw new Error(`useAction received a new \`run\` function on ${UNCOMMITTED_CHANGES} renders in a row. \`run\` is the action's identity and must stay the same function between renders: pass a bound command such as \`api.rename.run\` directly, or wrap your function in \`useCallback\` or \`useMemo\`.`);
|
|
17
|
+
}
|
|
18
|
+
see({ changes, run });
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=useStableRun.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStableRun.js","sourceRoot":"","sources":["../../../src/client/adapters/useStableRun.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE7D,yIAAyI;AACzI,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,MAAM,UAAU,YAAY,CAAC,GAAY;IACxC,2HAA2H;IAC3H,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IAClD,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAClC,kBAAkB,CAAC,GAAG,EAAE;QACvB,YAAY,CAAC,OAAO,GAAG,IAAI,CAAC;IAC7B,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IACX,IAAI,IAAI,CAAC,GAAG,KAAK,GAAG,EAAE,CAAC;QACtB,OAAO;IACR,CAAC;IACD,MAAM,OAAO,GAAG,IAAI,KAAK,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;IACrE,IAAI,OAAO,KAAK,mBAAmB,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CACd,gDAAgD,mBAAmB,yNAAyN,CAC5R,CAAC;IACH,CAAC;IACD,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;AACvB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.0",
|
|
4
4
|
"description": "React query, action, editor and session hooks for native Effect atoms",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@shivaedev/access": "0.6.3",
|
|
49
|
-
"@shivaedev/contract": "0.
|
|
49
|
+
"@shivaedev/contract": "0.45.0",
|
|
50
50
|
"@shivaedev/errors": "0.12.0",
|
|
51
51
|
"@shivaedev/form": "0.19.3",
|
|
52
|
-
"@shivaedev/identity": "0.32.
|
|
52
|
+
"@shivaedev/identity": "0.32.1"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@effect/atom-react": "4.1.2",
|
|
@@ -57,14 +57,14 @@
|
|
|
57
57
|
"@effect/sql-pg": "4.1.2",
|
|
58
58
|
"@effect/sql-sqlite-node": "4.1.2",
|
|
59
59
|
"@shivaedev/changes": "0.12.0",
|
|
60
|
-
"@shivaedev/jobs": "0.42.
|
|
61
|
-
"@shivaedev/quality": "0.78.
|
|
62
|
-
"@shivaedev/server": "0.34.
|
|
60
|
+
"@shivaedev/jobs": "0.42.3",
|
|
61
|
+
"@shivaedev/quality": "0.78.1",
|
|
62
|
+
"@shivaedev/server": "0.34.2",
|
|
63
63
|
"@shivaedev/service": "0.9.1",
|
|
64
|
-
"@shivaedev/sql": "0.
|
|
65
|
-
"@shivaedev/test-kits": "0.
|
|
66
|
-
"@shivaedev/test-sql": "0.25.
|
|
67
|
-
"@shivaedev/test-story": "0.47.
|
|
64
|
+
"@shivaedev/sql": "0.48.0",
|
|
65
|
+
"@shivaedev/test-kits": "0.13.0",
|
|
66
|
+
"@shivaedev/test-sql": "0.25.1",
|
|
67
|
+
"@shivaedev/test-story": "0.47.2",
|
|
68
68
|
"@tanstack/react-router": "1.170.46",
|
|
69
69
|
"@types/node": "24.19.2",
|
|
70
70
|
"@types/react": "19.3.0",
|
|
@@ -4,6 +4,7 @@ import type * as Atom from "effect/reactivity/Atom";
|
|
|
4
4
|
import { useContext, useInsertionEffect, useMemo, useRef } from "react";
|
|
5
5
|
import { isUnauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
6
6
|
import type { AtomServices } from "#AtomServices.ts";
|
|
7
|
+
import { useStableRun } from "#client/adapters/useStableRun.ts";
|
|
7
8
|
import { NoticeContext } from "#client/NoticeContext.ts";
|
|
8
9
|
import type { NoticeFeedback } from "#client/notices.ts";
|
|
9
10
|
import { useSessionRecheck } from "#client/sessionBoundary.ts";
|
|
@@ -21,6 +22,7 @@ export function useActionSource<TInput, A, E, R, TRuntimeError>(
|
|
|
21
22
|
run: ((input: TInput) => Effect.Effect<A, E, AtomServices<R>>) | undefined,
|
|
22
23
|
options: ActionOptions<TInput, A, E, R>,
|
|
23
24
|
): Atom.AtomResultFn<TInput, A, E | TRuntimeError> {
|
|
25
|
+
useStableRun(run);
|
|
24
26
|
const registry = useContext(RegistryContext);
|
|
25
27
|
const recheck = useSessionRecheck();
|
|
26
28
|
const notices = useContext(NoticeContext);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { useAtomValue } from "@effect/atom-react";
|
|
2
|
+
import { type ActiveClient, clientActivity } from "@shivaedev/contract/clientActivity.ts";
|
|
3
|
+
|
|
4
|
+
export function useFirstSettled(client: ActiveClient): boolean {
|
|
5
|
+
return useAtomValue(clientActivity(client).firstSettled);
|
|
6
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useInsertionEffect, useRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
// A deliberate swap changes `run` once and commits; React itself stops a component after 25 uncommitted renders without naming the hook.
|
|
4
|
+
const UNCOMMITTED_CHANGES = 10;
|
|
5
|
+
|
|
6
|
+
export function useStableRun(run: unknown) {
|
|
7
|
+
// State, unlike a ref, is discarded with an abandoned render, so only renders React repeats before one commit are counted.
|
|
8
|
+
const [seen, see] = useState({ changes: 0, run });
|
|
9
|
+
const committedRef = useRef(seen);
|
|
10
|
+
useInsertionEffect(() => {
|
|
11
|
+
committedRef.current = seen;
|
|
12
|
+
}, [seen]);
|
|
13
|
+
if (seen.run === run) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const changes = seen === committedRef.current ? 1 : seen.changes + 1;
|
|
17
|
+
if (changes === UNCOMMITTED_CHANGES) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
`useAction received a new \`run\` function on ${UNCOMMITTED_CHANGES} renders in a row. \`run\` is the action's identity and must stay the same function between renders: pass a bound command such as \`api.rename.run\` directly, or wrap your function in \`useCallback\` or \`useMemo\`.`,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
see({ changes, run });
|
|
23
|
+
}
|