Xstate: [@xstate/react] rc.4 doesn't run actions when sending events from parent to child

Created on 14 Apr 2020  路  3Comments  路  Source: davidkpiano/xstate

Description
xstate/[email protected] causes an issue with sending events from a parent machine to a child machine.

Expected Result
Sending an event from the parent machine to the child machine causes the child to transition and fire any actions associated with the transition.

Actual Result
The child seems to transition to the new state but doesn't run the actions

Reproduction
Steps to reproduce:

  1. Go to sandbox https://codesandbox.io/s/xstate-react-reddit-example-with-actors-x4nk0?file=/src/machine.js
  2. Using rc.4, clicking the button doesn't run the action
  3. Using rc.3 (make sure to refresh sandbox), clicking the button runs the action

Additional context
Happens in xstate/[email protected]
Works in xstate/[email protected]

bug

Most helpful comment

Verified this - it's because invoked machines inherit options from the parent, and in rc.4, execute is set to false (because React executes side-effects in useEffect) and that is set in child interpreters as well.

The fix here is to _not_ inherit the execute option. Will fix soon.

All 3 comments

Verified this - it's because invoked machines inherit options from the parent, and in rc.4, execute is set to false (because React executes side-effects in useEffect) and that is set in child interpreters as well.

The fix here is to _not_ inherit the execute option. Will fix soon.

What's the current workaround for this? Currently using:
@xstate/react: 1.0.0-rc.6
xstate: 4.12.0

@cybervaldez This seems to be working in the latest XState 4.12 and @xstate/react 1.0.0-rc.6: https://codesandbox.io/s/xstate-react-reddit-example-with-actors-forked-7k3zk?file=/src/machine.js

Closing this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pke picture pke  路  3Comments

ifokeev picture ifokeev  路  3Comments

mattiamanzati picture mattiamanzati  路  3Comments

bradwoods picture bradwoods  路  3Comments

jfun picture jfun  路  3Comments