Description
assign() is calling its functions multiple times.
Expected Result
assign() should call its functions just once.
Actual Result
assign() is calling its functions multiple times. A side effect of that is that when using spawn() we end up with multiple instances of the same spawned machine:
Reproduction
https://codesandbox.io/s/xstate-react-template-1u2b4
Additional context
Looks like this problem was introduced by v4.7.0, it's working perfectly in v4.6.7: https://codesandbox.io/s/xstate-react-template-44r3j
Thanks for the report - going to take a look at this in few hours
Thank you very much @Andarist 馃檹
I gave this a quick look right now and I don't immediately see that this would end up with multiple spawned machines. Could you list repro steps for observing this?
The reason why this gets executed multiple times are excessive .initialState reads - which are not ideal and I'm going to fix them, but they should be pure and shouldn't result in spawning new child machines.
@Andarist if you open the first CodeSandbox URL (https://1u2b4.csb.app) and open your Redux DevTools you'll see that it actually has many instances for the spawned machine.
Maybe it's a bug with the devTools integration.
Using XState 4.7.2
I just ran into this and was not using the redux devtools. Seems to be isolated to assign and not spawn. If I use a callback as an action I don't get this behavior.

@Jpadilla1 yes, it seems like the same problem. It got fixed by it has not yet been released. Keep in mind that it shouldn't affect the overall behavior of your app as assign should be pure.
It got fixed by it has not yet been released. Keep in mind that it shouldn't affect the overall behavior of your app as assign should be pure.
@Andarist could you happen to link to the git commit for this? Just wanted to try it out locally!
@chrisdhanaraj Try out the latest XState 4.7.3 and see if it fixes it!
@davidkpiano @chrisdhanaraj hm it's still happening for me on 4.7.3 (example)
@davidkpiano the issue was in @xstate/react