Description
Ran into this exception today, and I was baffled. I'm not doing any cascading dispatches, or calling dispatch inside of an observer, etc.
After digging through a bit I discovered that an isDispatching
flag is being toggled inside the reactor. Practically, that makes sense, since dispatches are supposed to be synchronous. However, a change observer's handler may be async, which opens up the potential for the flag not yet having been switched by the time another, completely separate action has been dispatched, resulting in this error.
That's exactly what was happening with my app. Larger React apps (like the one I'm working on) are especially vulnerable because setState
is async and goes through batching. Of course, setState
is used extensively, even by the nuclear react mixin/nuclear component.
More in general though, I think the current implementation makes it unsafe to write async code if relying on dispatching events, because you'll never truly know if that flag has been switched properly.
Potential fix could be just switching the way or moment in which the flag is toggled. Talking with a work colleague, however, we think some form of tick management might be more robust.
isDispatching
logic was introduced here: fad1ef9