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

Bug: Exit action triggered twice when invoked machine escalates from final state #4167

Closed
andrejpavlovic opened this issue Jul 29, 2023 · 0 comments · Fixed by #4376
Closed

Comments

@andrejpavlovic
Copy link

andrejpavlovic commented Jul 29, 2023

Description

If a child machine has a top-level exit action, this action will be triggered twice when the child machine ends in a final state that triggers an escalate action.

Basically a child machine like this one will trigger exit action twice when reaching final cancelled state.

const childMachine = createMachine({
  predictableActionArguments: true,
  id: "child",
  initial: "start",
  entry: () => {
    console.log('child-entry')
  },
  exit: () => { // <-- triggered twice when reaching final `cancelled` state
    console.log('child-exit')
  },
  states: {
    start: {
      on: {
        COMPLETE: "completed",
        CANCEL: "cancelled"
      }
    },
    completed: {
      type: "final"
    },
    cancelled: { // <-- final cancelled state
      type: "final",
      entry: actions.escalate({ type: "cancelled" })
    }
  }
});

send('CANCEL')

Expected result

child-entry
child-exit

Actual result

child-entry
child-exit
child-exit

Reproduction

https://codesandbox.io/s/ecstatic-euler-pqtsfj?file=/src/index.js

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants