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

Combinatorial machines enter infinite loop #2176

Closed
VanTanev opened this issue May 6, 2021 · 1 comment · Fixed by #2149
Closed

Combinatorial machines enter infinite loop #2176

VanTanev opened this issue May 6, 2021 · 1 comment · Fixed by #2149

Comments

@VanTanev
Copy link
Contributor

VanTanev commented May 6, 2021

Description
A combinatorial machine enters an infinite loop when a root service sends back an event that updates the context.

const machine = createMachine({
  id: "machine",
  context: {
    name: ""
  },
  invoke: {
    id: "name-observer",
    src: () => (sendBack) => {
      // This service is re-initialized on each context change if `states` is not set on the machine.
      // This causes it to send back the SET_NAME event again, and we enter an infinite loop.
      sendBack({ type: "SET_NAME", name: "John" });
    }
  },
  on: {
    SET_NAME: { actions: assign((ctx, { name }) => ({ name })) }
  }

  // if the following is uncommented, the machine does not go into infinite loop:

  // initial: "inactive",
  // states: {
  //   inactive: {}
  // }
});

Expected Result
Combinatorial machines should behave like normal machines. The root invoke service should not be re-initialized on each machine change.

Reproduction
https://codesandbox.io/s/vigilant-butterfly-bi1ei?file=/src/index.js

Additional context
XState 4.19.1

@davidkpiano
Copy link
Member

Duplicate of #2147, will be fixed soon in #2149

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

Successfully merging a pull request may close this issue.

2 participants