wix-incubator / repluggable

Pluggable micro frontends in React+Redux apps
MIT License
172 stars 13 forks source link

Notify if needed before deferring subscriber notifications #251

Closed ShirShintel closed 8 months ago

ShirShintel commented 8 months ago

This PR fixes a bug with deferSubscriberNotifications, where it's called right after a state update.

In general, when dispatching a state update, we update pendingBroadcastNotification and notify all on the next animation frame. When calling deferSubscriberNotifications right after a dispatch, we face with a case where we should have notified subscribers, but there was no animation frame yet, and so we start deferring notification before notifying on the previous state update. Meaning, we do not notify about the state update that happened right before we started deferring until we stop deferring all notifications.

This is an unexpected behaviour, and to solve this, this PR adds executes all pending actions before starting to defer notifications, in case there are pending subscribers\observables\flush.