xstate-tools icon indicating copy to clipboard operation
xstate-tools copied to clipboard

Visual editor overwrites data property in invoked machines

Open idosal opened this issue 2 years ago • 4 comments

Hey, I've recently started experimenting with the Visual Editor. It's mind-blowingly cool! Unfortunately, I ran into a bug - In one of the states, I invoke a child machine with an initial context:

someState: {
                    invoke: {
                        id: 'childMachine',
                        src: 'childMachine',
                        data: {
                            someContext: (ctx: any, _: any) => ctx.someContext,
                        },
                       ...
                    },
                }

When I launch the Visual Editor, it rewrites this portion, omitting the data property. The result is:

someState: {
                    invoke: {
                        id: 'childMachine',
                        src: 'childMachine',
                        ...
                    },
                }

I'd be happy to provide additional information if needed.

I thought it might have something to do with the Invoke config, so I created a PR. I hope it helps.

idosal avatar Feb 26 '22 21:02 idosal

Just adding my experience here... I too see that the data param is clobbered when using the visual editor in vscode. Quite a nasty little issue!

To reproduce,

  1. create a state machine with a final state, and provide that state with a data parameter
  2. open the visual editor in vs code
  3. use the autolayout feature
  4. notice that the data parameter has been removed

For example:

const Machine = createMachine({
  initial: "Start",
  states: {
    Start: {
      on: {
        "DONE": "End"
      }
    },
    End: {
      type: "final",
      data: (context, event) => "some data"
    }
  }
})

After autolayout, data is clobbered :(

const Machine = createMachine({
  initial: "Start",
  states: {
    Start: {
      on: {
        "DONE": "End"
      }
    },
    End: {
      type: "final"
    }
  }
})

EDIT: This data param is clobbered from all states, not just the final state.

jorgenbuilder avatar Jul 27 '22 17:07 jorgenbuilder

We are aware of this issue and we are working on a comprehensive fix for this and related issues.

Andarist avatar Jul 27 '22 19:07 Andarist

Any news on this one?

joffarex avatar Sep 14 '22 09:09 joffarex

I'm working on this. We are going to release a major update of the extension in the upcoming weeks and that will resolve this issue.

Andarist avatar Sep 14 '22 09:09 Andarist