Bug.
Synced actors are dispatching a (potentially) unnecessary update.
When spawning a synced actor the initial xstate.update event should wait till the parent initializes.
When spawning a synced actor the initial xstate.update event is being dispatched before the parent initializes.
While maybe sharing initial state of the synced actor could be done in other way than with dispatching xstate.update the problem itself seems a little bit bigger - any event dispatched to the parent in such a scenario is causing a warning to be printed out. Demo with additional sendParent used - https://codesandbox.io/s/xstate-bug-report-534-1fdx4
The good thing is that the code actually works OK, it's only a warning which tries to be helpful, but in this case is inappropriate.
After quick debugging session though I see that the problem is that interpret call executes actions (should it?), so it starts the child machine which in turn send an event to the parent which is not yet initialized as its start wasn't yet called. Seems to me like interpret should be more lazy about the stuff it does at initialization time, WDYT @davidkpiano ?
Seems to me like interpret should be more lazy about the stuff it does at initialization time
Yes, it should. I'll be making changes around this behavior soon.
Most helpful comment
While maybe sharing initial state of the synced actor could be done in other way than with dispatching
xstate.updatethe problem itself seems a little bit bigger - any event dispatched to the parent in such a scenario is causing a warning to be printed out. Demo with additionalsendParentused - https://codesandbox.io/s/xstate-bug-report-534-1fdx4The good thing is that the code actually works OK, it's only a warning which tries to be helpful, but in this case is inappropriate.
After quick debugging session though I see that the problem is that
interpretcall executes actions (should it?), so it starts the child machine which in turn send an event to the parent which is not yet initialized as its start wasn't yet called. Seems to me likeinterpretshould be more lazy about the stuff it does at initialization time, WDYT @davidkpiano ?