Xstate: Synced actors are dispatching a (potentially) unnecessary update

Created on 11 Jul 2019  路  2Comments  路  Source: davidkpiano/xstate

Bug or feature request?

Bug.

Description:

Synced actors are dispatching a (potentially) unnecessary update.

(Bug) Expected result:

When spawning a synced actor the initial xstate.update event should wait till the parent initializes.

(Bug) Actual result:

When spawning a synced actor the initial xstate.update event is being dispatched before the parent initializes.

Link to reproduction or proof-of-concept:

https://codesandbox.io/s/xstate-bug-report-534-jw0i1

Most helpful comment

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 ?

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

suku-h picture suku-h  路  3Comments

rodinhart picture rodinhart  路  3Comments

drmikecrowe picture drmikecrowe  路  3Comments

3plusalpha picture 3plusalpha  路  3Comments

hnordt picture hnordt  路  3Comments