xstate-tools
xstate-tools copied to clipboard
Visual editor overwrites data property in invoked machines
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.
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,
- create a state machine with a final state, and provide that state with a
data
parameter - open the visual editor in vs code
- use the autolayout feature
- 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.
We are aware of this issue and we are working on a comprehensive fix for this and related issues.
Any news on this one?
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.