Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update xstate monorepo to v5 (major) #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Jun 4, 2023

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
@xstate/react (source) 0.8.1 -> 5.0.2 age adoption passing confidence
xstate (source) 4.38.3 -> 5.19.2 age adoption passing confidence

Release Notes

statelyai/xstate (@​xstate/react)

v5.0.2

Compare Source

Patch Changes

v5.0.1

Compare Source

Patch Changes

v5.0.0

Compare Source

Patch Changes

v4.1.3

Compare Source

Patch Changes

v4.1.2

Compare Source

Patch Changes
  • #​5055 ad38c35c37 Thanks @​SandroMaglione! - Updated types of useActor, useMachine, and useActorRef to require input when defined inside types/input.

    Previously even when input was defined inside types, useActor, useMachine, and useActorRef would not make the input required:

    const machine = setup({
      types: {
        input: {} as { value: number }
      }
    }).createMachine({});
    
    function App() {
      // Event if `input` is not defined, `useMachine` works at compile time, but risks crashing at runtime
      const _ = useMachine(machine);
      return <></>;
    }

    With this change the above code will show a type error, since input is now required:

    const machine = setup({
      types: {
        input: {} as { value: number }
      }
    }).createMachine({});
    
    function App() {
      const _ = useMachine(machine, {
        input: { value: 1 } // Now input is required at compile time!
      });
      return <></>;
    }

    This avoids runtime errors when forgetting to pass input when defined inside types.

v4.1.1

Compare Source

Patch Changes
  • #​4844 5aa6eb05c Thanks @​davidkpiano! - The useSelector(…) hook from @xstate/react is now compatible with stores from @xstate/store.

    import { createStore } from '@&#8203;xstate/store';
    import { useSelector } from '@&#8203;xstate/react';
    
    const store = createStore(
      {
        count: 0
      },
      {
        inc: {
          count: (context) => context.count + 1
        }
      }
    );
    
    function Counter() {
      // Note that this `useSelector` is from `@xstate/react`,
      // not `@xstate/store/react`
      const count = useSelector(store, (state) => state.context.count);
    
      return (
        <div>
          <button onClick={() => store.send({ type: 'inc' })}>{count}</button>
        </div>
      );
    }

v4.1.0

Compare Source

Minor Changes
  • #​4231 c2402e7bc Thanks @​davidkpiano! - The actor passed to useSelector(actor, selector) is now allowed to be undefined for an actor that may not exist yet. For actors that may be undefined, the snapshot provided to the selector function can also be undefined:

    const count = useSelector(maybeActor, (snapshot) => {
      // `snapshot` may be undefined
      return snapshot?.context.count;
    });
    
    count; // number | undefined

v4.0.3

Compare Source

Patch Changes
  • #​4695 52900a084 Thanks @​davidkpiano! - Options in createActorContext are now properly merged with provider options. Previously, provider options replaced the actor options.

    const { inspect } = createBrowserInspector();
    
    const SomeContext = createActorContext(someMachine, { inspect });
    
    // ...
    // Options are now merged:
    // { inspect: inspect, input: 10 }
    <SomeContext.Provider options={{ input: 10 }}>
      {/* ... */}
    </SomeContext.Provider>;

v4.0.2

Compare Source

Patch Changes

v4.0.1

Compare Source

Patch Changes
  • #​4497 d7f220225 Thanks @​davidkpiano! - Fix an issue where after transitions do not work in React strict mode. Delayed events (including from after transitions) should now work as expected in all React modes.

v4.0.0

Compare Source

Major Changes
  • #​3947 5fa3a0c74 Thanks @​davidkpiano! - Removed the ability to pass a factory function as argument to useMachine.

  • #​4006 42df9a536 Thanks @​davidkpiano! - useActorRef is introduced, which returns an ActorRef from actor logic:

    const actorRef = useActorRef(machine, { ... });
    const anotherActorRef = useActorRef(fromPromise(...));

    ~~useMachine~~ is deprecated in favor of useActor, which works with machines and any other kind of logic

    -const [state, send] = useMachine(machine);
    +const [state, send] = useActor(machine);
    const [state, send] = useActor(fromTransition(...));

    ~~useSpawn~~ is removed in favor of useActorRef

    -const actorRef = useSpawn(machine);
    +const actorRef = useActorRef(machine);
    
    The previous use of `useActor(actorRef)` is now replaced with just using the `actorRef` directly, and with `useSelector`:
    
    ```diff
    -const [state, send] = useActor(actorRef);
    +const state = useSelector(actorRef, s => s);
    // actorRef.send(...)
  • #​4050 fc88dc8e6 Thanks @​davidkpiano! - The options prop has been added (back) to the Context.Provider component returned from createActorContext:

    const SomeContext = createActorContext(someMachine);
    
    // ...
    
    <SomeContext.Provider options={{ input: 42 }}>
      {/* ... */}
    </SomeContext.Provider>;
  • #​4006 42df9a536 Thanks @​davidkpiano! - useActor has been removed from the created actor context, you should be able to replace its usage with MyCtx.useSelector and MyCtx.useActorRef.

  • #​4265 1153b3f9a Thanks @​davidkpiano! - FSM-related functions have been removed.

  • #​3947 5fa3a0c74 Thanks @​davidkpiano! - Implementations for machines on useMachine hooks should go directly on the machine via machine.provide(...), and are no longer allowed to be passed in as options.

    -const [state, send] = useMachine(machine, {
    -  actions: {
    -    // ...
    -  }
    -});
    +const [state, send] = useMachine(machine.provide({
    +  actions: {
    +    // ...
    +  }
    +}));
  • #​3148 7a68cbb61 Thanks @​davidkpiano! - Removed getSnapshot parameter from hooks. It is expected that the received actorRef has to have a getSnapshot method on it that can be used internally.

Minor Changes

v3.2.2

Compare Source

Patch Changes

v3.2.1

Compare Source

Patch Changes

v3.2.0

Compare Source

Minor Changes
  • #​3814 494203b3d Thanks @​Andarist! - The Provider from createActorContext(...) now accepts the options={{...}} prop that takes the same object as the second argument to the useMachine(machine, options) hook.

    These options are no longer passed as the second argument to the createActorContext(machine) function:

    -const SomeContext = createActorContext(someMachine,
    -  { actions: { ... } });
    +const SomeContext = createActorContext(someMachine);
    
    // ...
    
    -<SomeContext.Provider>
    +<SomeContext.Provider options={{ actions: { ... } }}>
    
    // ...

v3.1.2

Compare Source

Patch Changes
  • #​4844 5aa6eb05c Thanks @​davidkpiano! - The useSelector(…) hook from @xstate/react is now compatible with stores from @xstate/store.

    import { createStore } from '@&#8203;xstate/store';
    import { useSelector } from '@&#8203;xstate/react';
    
    const store = createStore(
      {
        count: 0
      },
      {
        inc: {
          count: (context) => context.count + 1
        }
      }
    );
    
    function Counter() {
      // Note that this `useSelector` is from `@xstate/react`,
      // not `@xstate/store/react`
      const count = useSelector(store, (state) => state.context.count);
    
      return (
        <div>
          <button onClick={() => store.send({ type: 'inc' })}>{count}</button>
        </div>
      );
    }

v3.1.1

Compare Source

Patch Changes

v3.1.0

Compare Source

Minor Changes
  • #​4231 c2402e7bc Thanks @​davidkpiano! - The actor passed to useSelector(actor, selector) is now allowed to be undefined for an actor that may not exist yet. For actors that may be undefined, the snapshot provided to the selector function can also be undefined:

    const count = useSelector(maybeActor, (snapshot) => {
      // `snapshot` may be undefined
      return snapshot?.context.count;
    });
    
    count; // number | undefined

v3.0.2

Compare Source

Patch Changes
  • #​3752 4190c3fd6 Thanks @​davidkpiano! - Computing the initial state is now consistent with useMachine and useActor, avoiding stale initial state problems with nested machines

v3.0.1

Compare Source

Patch Changes

v3.0.0

Compare Source

Major Changes
  • #​4288 cfdf754f8 Thanks @​davidkpiano! - The useMachine(machine) hook now returns { snapshot, send, actorRef } instead of { state, send, service }:

    const {
    - state,
    + snapshot,
      send,
    - service
    + actorRef
    } = useMachine(machine);
  • #​3148 7a68cbb61 Thanks @​davidkpiano! - Removed getSnapshot parameter from composables. It is expected that the received actorRef has to have a getSnapshot method on it that can be used internally.

  • #​4265 1153b3f9a Thanks @​davidkpiano! - FSM-related functions have been removed.

Minor Changes
  • #​3727 5fb3c683d Thanks @​Andarist! - exports field has been added to the package.json manifest. It limits what files can be imported from a package - it's no longer possible to import from files that are not considered to be a part of the public API.
  • #​4288 cfdf754f8 Thanks @​davidkpiano! - The useInterpret(machine) and useSpawn(machine) hooks have been removed; use the useActorRef(machine) hook instead.

v2.0.1

Compare Source

Patch Changes
  • #​3089 862697e29 Thanks @​Andarist! - Fixed compatibility with Skypack by exporting some shared utilities from root entry of XState and consuming them directly in other packages (this avoids accessing those things using deep imports and thus it avoids creating those compatibility problems).

v2.0.0

Compare Source

Major Changes
  • #​5000 eeadb7121 Thanks @​TkDodo! - - Replace use-sync-external-store/shim with useSyncExternalStore from React.
    • Do not memoize getSnapshot in useSyncExternalStore.
    • Implement getServerSnapshot in useSyncExternalStore.
    • Expect store to always be defined in useSelector
    • Update React types to v18 and testing library to v16.

v1.6.3

Compare Source

Patch Changes

v1.6.2

Compare Source

Patch Changes
  • #​2736 2246ae051 Thanks @​Andarist, @​davidkpiano, @​VanTanev! - The useSelector(...) hook now works as expected when the actor passed in changes. The hook will properly subscribe to the new actor and select the desired value. See #​2702

  • #​2685 469268d39 Thanks @​farskid, @​Andarist! - Fixed a regression with a development-only warning not being shown when a machine reference is updated during the hook lifecycle. This usually happens when machine options are dependent on external values and they're passed via withConfig.

    const machine = createMachine({
      initial: 'foo',
      context: { id: 1 },
      states: {
        foo: {
          on: {
            CHECK: {
              target: 'bar',
              cond: 'hasOverflown'
            }
          }
        },
        bar: {}
      }
    });
    
    const [id, setId] = useState(1);
    const [current, send] = useMachine(
      machine.withConfig({
        guards: {
          hasOverflown: () => id > 1 // id is a reference to an outside value
        }
      })
    );
    
    // later when id updates
    setId(2);
    // Now the reference passed to `useMachine` (the result of `machine.withConfig`) is updated but the interpreted machine stays the same. So the guard is still the previous one that got passed to the `useMachine` initially, and it closes over the stale `id`.

v1.6.1

Compare Source

Patch Changes

v1.6.0

Compare Source

Minor Changes
  • 4b4872ca #​2241 Thanks @​mattpocock! - Changed the behaviour of guards, delays and activities when declared as options in useMachine/useInterpret.

    Previously, guards could not reference external props, because they would not be updated when the props changed. For instance:

    const Modal = props => {
      useMachine(modalMachine, {
        guards: {
          isModalOpen: () => props.isOpen
        }
      });
    };

    When the component is created, props.isOpen would be checked and evaluated to the initial value. But if the guard is evaluated at any other time, it will not respond to the props' changed value.

    This is not true of actions/services. This will work as expected:

    const Modal = props => {
      useMachine(modalMachine, {
        actions: {
          consoleLogModalOpen: () => {
            console.log(props.isOpen);
          }
        }
      });
    };

    This change brings guards and delays into line with actions and services.

    ⚠️ NOTE: Whenever possible, use data from within context rather than external data in your guards and delays.

Patch Changes
  • fe3e859f #​2522 Thanks @​farskid, @​Andarist! - Fixed an issue with actors not being spawned correctly by useMachine and useInterpret when they were defined a lazily evaluated context, like for example here:

    createMachine({
      // lazy context
      context: () => ({
        ref: spawn(() => {})
      })
    });

v1.5.1

Compare Source

Patch Changes
  • 453acacb #​2389 Thanks @​davidkpiano! - An internal issue where the spawnBehavior import for the useSpawn(...) hook was broken internally has been fixed.

v1.5.0

Compare Source

Minor Changes
  • 432b60f7 #​2280 Thanks @​davidkpiano! - Just like useInterpret(...), other types of actors can now be spawned from behaviors using useSpawn(...):

    import { fromReducer } from 'xstate/lib/behaviors';
    import { useActor, useSpawn } from '@&#8203;xstate/react';
    
    type CountEvent = { type: 'INC' } | { type: 'DEC' };
    
    const countBehavior = fromReducer(
      (count: number, event: CountEvent): number => {
        if (event.type === 'INC') {
          return count + 1;
        } else if (event.type === 'DEC') {
          return count - 1;
        }
    
        return count;
      },
      0 // initial state
    );
    
    const Component = () => {
      const countActorRef = useSpawn(countBehavior);
      const [count, send] = useActor(countActorRef);
    
      return (
        <div>
          Count: {count}
          <button onClick={() => send({ type: 'INC' })}>Increment</button>
          <button onClick={() => send({ type: 'DEC' })}>Decrement</button>
        </div>
      );
    };

v1.4.0

Compare Source

Minor Changes
  • 849ec56c #​2286 Thanks @​davidkpiano! - The useService(...) hook will be deprecated, since services are also actors. In future versions, the useActor(...) hook should be used instead:

    -const [state, send] = useService(service);
    +const [state, send] = useActor(service);
Patch Changes
  • ea3aaffb #​2326 Thanks @​davidkpiano! - The send type returned in the tuple from useActor(someService) was an incorrect never type; this has been fixed.

v1.3.4

Compare Source

Patch Changes
  • aa3c2991 #​2223 Thanks @​davidkpiano! - Support for actor refs with the .getSnapshot() method (added for spawned actors in XState version 4.19) is now supported in the useActor(...) hook.

v1.3.3

Compare Source

Patch Changes
  • 27e7242c #​2112 Thanks @​davidkpiano! - The executeEffect function is no longer exported (was meant to be internal and is useless as a public function anyway). This also fixes a circular dependency issue.

v1.3.2

Compare Source

Patch Changes
  • bb5e81ea #​2050 Thanks @​theKashey! - Added an explicit entrypoint for @xstate/react/fsm which you can use instead of @xstate/react/lib/fsm. This is the only specifier that will be supported in the future - the other one will be dropped in the next major version.

    -import { useMachine } from '@&#8203;xstate/react/lib/fsm'
    +import { useMachine } from '@&#8203;xstate/react/fsm'

v1.3.1

Compare Source

Patch Changes
  • b076b253 #​1947 Thanks @​lukekarrys! - Fix typing of the service returned from the fsm useMachine hook by passing it Typestate

  • 9b5dc784 #​1950 Thanks @​Andarist! - Fixed an issue with toObserver being internally imported from xstate/lib/utils which has broken UMD build and the declared peer dep contract.

v1.3.0

Compare Source

Minor Changes
  • 577ae023 #​1915 Thanks @​davidkpiano! - New hook: useInterpret(machine), which is a low-level hook that interprets the machine and returns the service:

    import { useInterpret } from '@&#8203;xstate/react';
    import { someMachine } from '../path/to/someMachine';
    
    const App = () => {
      const service = useInterpret(someMachine);
    
      // ...
    };
  • 577ae023 #​1915 Thanks @​davidkpiano! - New hook: useSelector(actor, selector), which subscribes to actor and returns the selected state derived from selector(snapshot):

    import { useSelector } from '@&#8203;xstate/react';
    
    const App = ({ someActor }) => {
      const count = useSelector(someActor, state => state.context.count);
    
      // ...
    };

v1.2.2

Compare Source

Patch Changes

v1.2.1

Compare Source

Patch Changes

v1.2.0

Compare Source

Minor Changes

v1.1.0

Compare Source

Minor Changes
  • 89f9c27c #​1622 Thanks @​davidkpiano! - Spawned/invoked actors and interpreters are now typed as extending ActorRef rather than Actor or Interpreter. This unification of types should make it more straightforward to provide actor types in React:

    import { ActorRef } from 'xstate';
    import { useActor } from '@&#8203;xstate/react';
    
    const Child: React.FC<{ actorRef: ActorRef<SomeEvent, SomeEmitted> }> = ({
      actorRef
    }) => {
      // `state` is typed as `SomeEmitted`
      // `send` can be called with `SomeEvent` values
      const [state, send] = useActor(actorRef);
    
      // . ..
    };

    It's also easier to specify the type of a spawned/invoked machine with ActorRefFrom:

    import { createMachine, ActorRefFrom } from 'xstate';
    import { useActor } from '@&#8203;xstate/react';
    
    const someMachine = createMachine<SomeContext, SomeEvent>({
      // ...
    });
    
    const Child: React.FC<{ someRef: ActorRefFrom<typeof someMachine> }> = ({
      someRef
    }) => {
      // `state` is typed as `State<SomeContext, SomeEvent>`
      // `send` can be called with `SomeEvent` values
      const [state, send] = useActor(someRef);
    
      // . ..
    };

v1.0.3

Compare Source

Patch Changes

v1.0.2

Compare Source

Patch Changes
  • c7927083 #​1516 Thanks @​davidkpiano! - The send function returned from the useService() now can take two arguments (an event type and payload), to match the behavior of @xstate/react version 0.x.

  • db77623a #​1516 Thanks @​davidkpiano! - The send value returned from the useService() hook will now accept a payload, which matches the signature of the send value returned from the useMachine() hook:

    const [state, send] = useService(someService);
    
    // ...
    
    // this is OK:
    send('ADD', { value: 3 });
    
    // which is equivalent to:
    send({ type: 'ADD', value: 3 });
  • 93f6db02 #​1594 Thanks @​Andarist! - Fixed an issue with internal setState in useService being called with 2 arguments instead of 1.

  • 72b0880e #​1504 Thanks @​Andarist! - Fixed issue with useService returning an initial state for services in their final states.

v1.0.1

Compare Source

Patch Changes
  • c0bd0407 #​1493 Thanks @​davidkpiano! - There will now be a descriptive error when trying to use an actor-like object in the useService() hook, where useActor() should be preferred:

    Attempted to use an actor-like object instead of a service in the useService() hook. Please use the useActor() hook instead.

All notable changes to this project will be documented in this file.

v1.0.0

Major Changes

Configuration

📅 Schedule: Branch creation - "after 10pm every weekday,every weekend,before 5am every weekday" (UTC), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about these updates again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch from 1b288fd to 27964a3 Compare December 1, 2023 20:04
@renovate renovate bot changed the title Update dependency @xstate/react to v3 Update xstate monorepo (major) Dec 1, 2023
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch 5 times, most recently from 6001474 to a0a3989 Compare December 9, 2023 16:32
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch 2 times, most recently from 6f6f675 to f8aa8b5 Compare December 18, 2023 02:13
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch 2 times, most recently from e237280 to 840f913 Compare December 24, 2023 06:06
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch 2 times, most recently from 237c950 to 4c943f8 Compare January 11, 2024 17:17
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch 2 times, most recently from 2744571 to cbbc1be Compare January 29, 2024 14:29
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch 3 times, most recently from 79a7037 to 61c0dc1 Compare February 13, 2024 01:05
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch 3 times, most recently from 1f0d4a0 to a188f50 Compare February 21, 2024 16:26
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch 4 times, most recently from e9e95c2 to f730f12 Compare March 3, 2024 03:46
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch from f730f12 to 83b431d Compare April 9, 2024 16:07
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch 2 times, most recently from 5622885 to 79e7a81 Compare April 17, 2024 01:20
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch from 79e7a81 to af12c99 Compare April 24, 2024 22:18
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch from af12c99 to 3dcbb72 Compare May 5, 2024 00:33
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch from 3dcbb72 to 7cb1131 Compare June 1, 2024 16:04
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch from 7cb1131 to d978cb3 Compare June 11, 2024 14:03
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch from d978cb3 to f7681f8 Compare June 22, 2024 10:40
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch from f7681f8 to 30393cf Compare July 13, 2024 03:44
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch 3 times, most recently from 839517e to 00fbf70 Compare July 31, 2024 16:24
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch 3 times, most recently from 3a985e8 to 6030999 Compare August 15, 2024 17:23
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch 2 times, most recently from cf42d43 to dcb0dfe Compare September 6, 2024 09:23
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch from dcb0dfe to 2386698 Compare September 21, 2024 07:22
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch from 2386698 to 4dd8a47 Compare November 12, 2024 18:26
@renovate renovate bot changed the title Update xstate monorepo (major) Update xstate monorepo to v5 (major) Nov 12, 2024
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch from 4dd8a47 to e55afb2 Compare December 24, 2024 21:40
@renovate renovate bot force-pushed the renovate/major-xstate-monorepo branch from e55afb2 to 1eb3bc3 Compare January 12, 2025 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants