@xstate/react 7.0.0-alpha.5 → 7.0.0-alpha.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.
@@ -31,9 +31,19 @@ function _interopNamespace(e) {
31
31
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
32
32
  var useIsomorphicLayoutEffect__default = /*#__PURE__*/_interopDefault(useIsomorphicLayoutEffect);
33
33
 
34
+ function isStateMachine(logic) {
35
+ return typeof logic.provide === 'function' && !!logic.config && !!logic.sources;
36
+ }
37
+
38
+ // The hook updates the sources of its machine on later renders. A per-hook
39
+ // copy keeps those updates from reaching the caller's machine, which may be
40
+ // shared by other actors.
41
+ function ownLogic(logic) {
42
+ return isStateMachine(logic) ? logic.provide({}) : logic;
43
+ }
34
44
  function useIdleActorRef(logic, ...[options]) {
35
45
  const [actorRef, setActorRef] = React.useState(() => {
36
- return xstate.createActor(logic, options);
46
+ return xstate.createActor(ownLogic(logic), options);
37
47
  });
38
48
  // An object whose identity changes only when React Fast Refresh re-renders
39
49
  // this component. Fast Refresh ignores dependency lists while it applies an
@@ -51,7 +61,9 @@ function useIdleActorRef(logic, ...[options]) {
51
61
  refreshSignalRef.current !== refreshSignal;
52
62
  refreshSignalRef.current = refreshSignal;
53
63
  if (logic.config === currentLogic.config) {
54
- currentLogic.sources = logic.sources;
64
+ if (isStateMachine(logic) && isStateMachine(currentLogic)) {
65
+ currentLogic.sources = logic.sources;
66
+ }
55
67
  return;
56
68
  }
57
69
  });
@@ -31,9 +31,19 @@ function _interopNamespace(e) {
31
31
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
32
32
  var useIsomorphicLayoutEffect__default = /*#__PURE__*/_interopDefault(useIsomorphicLayoutEffect);
33
33
 
34
+ function isStateMachine(logic) {
35
+ return typeof logic.provide === 'function' && !!logic.config && !!logic.sources;
36
+ }
37
+
38
+ // The hook updates the sources of its machine on later renders. A per-hook
39
+ // copy keeps those updates from reaching the caller's machine, which may be
40
+ // shared by other actors.
41
+ function ownLogic(logic) {
42
+ return isStateMachine(logic) ? logic.provide({}) : logic;
43
+ }
34
44
  function useIdleActorRef(logic, ...[options]) {
35
45
  const [actorRef, setActorRef] = React.useState(() => {
36
- return xstate.createActor(logic, options);
46
+ return xstate.createActor(ownLogic(logic), options);
37
47
  });
38
48
  // An object whose identity changes only when React Fast Refresh re-renders
39
49
  // this component. Fast Refresh ignores dependency lists while it applies an
@@ -51,7 +61,9 @@ function useIdleActorRef(logic, ...[options]) {
51
61
  const refreshed = refreshSignalRef.current !== refreshSignal;
52
62
  refreshSignalRef.current = refreshSignal;
53
63
  if (logic.config === currentLogic.config) {
54
- currentLogic.sources = logic.sources;
64
+ if (isStateMachine(logic) && isStateMachine(currentLogic)) {
65
+ currentLogic.sources = logic.sources;
66
+ }
55
67
  return;
56
68
  }
57
69
 
@@ -59,8 +71,9 @@ function useIdleActorRef(logic, ...[options]) {
59
71
  // defines the machine. Keep the running actor and carry its live snapshot
60
72
  // over to the new machine; start a fresh actor if it cannot be carried.
61
73
  if (refreshed) {
62
- if (!xstate._hotSwapActorLogic(actorRef, logic)) {
63
- setActorRef(xstate.createActor(logic, options));
74
+ const nextLogic = ownLogic(logic);
75
+ if (!xstate._hotSwapActorLogic(actorRef, nextLogic)) {
76
+ setActorRef(xstate.createActor(nextLogic, options));
64
77
  }
65
78
  }
66
79
  });
@@ -5,9 +5,19 @@ import { _toObserver, createActor, _hotSwapActorLogic } from 'xstate';
5
5
  import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';
6
6
  import { useSyncExternalStore } from 'use-sync-external-store/shim';
7
7
 
8
+ function isStateMachine(logic) {
9
+ return typeof logic.provide === 'function' && !!logic.config && !!logic.sources;
10
+ }
11
+
12
+ // The hook updates the sources of its machine on later renders. A per-hook
13
+ // copy keeps those updates from reaching the caller's machine, which may be
14
+ // shared by other actors.
15
+ function ownLogic(logic) {
16
+ return isStateMachine(logic) ? logic.provide({}) : logic;
17
+ }
8
18
  function useIdleActorRef(logic, ...[options]) {
9
19
  const [actorRef, setActorRef] = useState(() => {
10
- return createActor(logic, options);
20
+ return createActor(ownLogic(logic), options);
11
21
  });
12
22
  // An object whose identity changes only when React Fast Refresh re-renders
13
23
  // this component. Fast Refresh ignores dependency lists while it applies an
@@ -25,7 +35,9 @@ function useIdleActorRef(logic, ...[options]) {
25
35
  const refreshed = refreshSignalRef.current !== refreshSignal;
26
36
  refreshSignalRef.current = refreshSignal;
27
37
  if (logic.config === currentLogic.config) {
28
- currentLogic.sources = logic.sources;
38
+ if (isStateMachine(logic) && isStateMachine(currentLogic)) {
39
+ currentLogic.sources = logic.sources;
40
+ }
29
41
  return;
30
42
  }
31
43
 
@@ -33,8 +45,9 @@ function useIdleActorRef(logic, ...[options]) {
33
45
  // defines the machine. Keep the running actor and carry its live snapshot
34
46
  // over to the new machine; start a fresh actor if it cannot be carried.
35
47
  if (refreshed) {
36
- if (!_hotSwapActorLogic(actorRef, logic)) {
37
- setActorRef(createActor(logic, options));
48
+ const nextLogic = ownLogic(logic);
49
+ if (!_hotSwapActorLogic(actorRef, nextLogic)) {
50
+ setActorRef(createActor(nextLogic, options));
38
51
  }
39
52
  }
40
53
  });
@@ -5,9 +5,19 @@ import { _toObserver, createActor } from 'xstate';
5
5
  import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';
6
6
  import { useSyncExternalStore } from 'use-sync-external-store/shim';
7
7
 
8
+ function isStateMachine(logic) {
9
+ return typeof logic.provide === 'function' && !!logic.config && !!logic.sources;
10
+ }
11
+
12
+ // The hook updates the sources of its machine on later renders. A per-hook
13
+ // copy keeps those updates from reaching the caller's machine, which may be
14
+ // shared by other actors.
15
+ function ownLogic(logic) {
16
+ return isStateMachine(logic) ? logic.provide({}) : logic;
17
+ }
8
18
  function useIdleActorRef(logic, ...[options]) {
9
19
  const [actorRef, setActorRef] = useState(() => {
10
- return createActor(logic, options);
20
+ return createActor(ownLogic(logic), options);
11
21
  });
12
22
  // An object whose identity changes only when React Fast Refresh re-renders
13
23
  // this component. Fast Refresh ignores dependency lists while it applies an
@@ -25,7 +35,9 @@ function useIdleActorRef(logic, ...[options]) {
25
35
  refreshSignalRef.current !== refreshSignal;
26
36
  refreshSignalRef.current = refreshSignal;
27
37
  if (logic.config === currentLogic.config) {
28
- currentLogic.sources = logic.sources;
38
+ if (isStateMachine(logic) && isStateMachine(currentLogic)) {
39
+ currentLogic.sources = logic.sources;
40
+ }
29
41
  return;
30
42
  }
31
43
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xstate/react",
3
- "version": "7.0.0-alpha.5",
3
+ "version": "7.0.0-alpha.6",
4
4
  "description": "XState tools for React",
5
5
  "keywords": [
6
6
  "state",
@@ -54,12 +54,7 @@
54
54
  },
55
55
  "peerDependencies": {
56
56
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
57
- "xstate": "^6.0.0-alpha.68"
58
- },
59
- "peerDependenciesMeta": {
60
- "xstate": {
61
- "optional": true
62
- }
57
+ "xstate": "^6.0.0-alpha.70"
63
58
  },
64
59
  "dependencies": {
65
60
  "use-isomorphic-layout-effect": "^1.1.2",
@@ -74,7 +69,7 @@
74
69
  "react-dom": "^19.0.0",
75
70
  "rxjs": "^7.8.1",
76
71
  "zod": "^3.25.51",
77
- "xstate": "^6.0.0-alpha.68"
72
+ "xstate": "^6.0.0-alpha.70"
78
73
  },
79
74
  "scripts": {}
80
75
  }