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

getInitialSnapshot initialize the machine twice #4774

Open
asfktz opened this issue Feb 28, 2024 · 0 comments
Open

getInitialSnapshot initialize the machine twice #4774

asfktz opened this issue Feb 28, 2024 · 0 comments
Labels

Comments

@asfktz
Copy link

asfktz commented Feb 28, 2024

Bug or feature request?

Bug

Description:

When calling:

getInitialSnapshot(machine, { param: "test" });

It gets called twice:

  • 1st time - without input: undefined
  • 2nd time - with input: { param: "test" }

Also, if the machine invokes another actor, it throws:

proxyConsole.js:64 Error: Actor with system ID 'child' already exists.

Expected result:

That getInitialSnapshot will initialize the machine once with the provided input.

Reproduction

import { createMachine, fromCallback, getInitialSnapshot } from "xstate";

const machine = createMachine({
  context: ({ input }) => {
    console.log("input in context", input);
    return {};
  },
  invoke: {
    systemId: "child",
    src: fromCallback(() => {}),
  },
});

getInitialSnapshot(machine, { param: "test" });

https://codesandbox.io/p/sandbox/jolly-goodall-kg7858?file=%2Fsrc%2Findex.js

@Andarist Andarist added the bug label Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants