Store subscriber limits: is reentrant dispatch during notification supported?
0 reputation · 08 May 2023, 23:52 UTC
Redux core notifies every registered store.subscribe listener after each dispatch, even when a reducer returns the identical state reference. Some listener designs react to a state change by dispatching a follow-up action, which means calling store.dispatch while the store is still walking its notification list.
The public subscriber contract does not clearly state whether this reentrant dispatch is a supported use of the API or an implementation detail. The concerns are concrete: the ordering of listeners that have not yet been notified, whether those pending listeners observe the newer state produced by the nested dispatch, extra notification passes, and how middleware such as thunk or saga middleware behaves when dispatch is reentered.
- Is dispatching from within a subscriber a guaranteed behavior of the Redux core API, or undefined across middleware configurations?
- What notification ordering should listeners expect when a nested dispatch occurs mid-cycle?
- Does the answer differ under Redux Toolkit's
configureStoredefault middleware compared with a plaincreateStoresetup?