You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unexpected behavior when emitting actions synchronously
What is the current behavior?
When an epic dispatches an action synchronously, it will in turn synchronously call store.dispatch (https://github.com/redux-observable/redux-observable/blob/master/src/createEpicMiddleware.ts#L85). This means all reducers and epics will be called with the new action before the current action propagates through the remaining combined epics. This causes some confusion where the state$.value can differ from what would be expected (even inside the same state$ pipe).
If the current behavior is a bug, please provide the steps to reproduce and a minimal demo of the problem using JSBin, StackBlitz, or similar.
(action$, state$, dependencies) => {
const initialState = state$.value; // Initial state
return state$.pipe(
tap(state => console.log(state === initialState), // Will return false
startWith(actionToChangeState) // This action will be run through the reducers before state$ is subscribed to above
)
}
What is the expected behavior?
I would expect the epics to dispatch actions after the current action/state has been passed to each epic in combine epics.
However I understand this has probably been around for a while, and may only crop up in more complex use cases (with multiple epics).
A workaround is to add delay(1) to the end of any epic that dispatches synchronously (specifically in response to an emit on state$ or action$).
If this is unlikely to be fixed it may be good to have it added to a "known issues" section in the docs?
Which versions of redux-observable, and which browser and OS are affected by this issue? Did this work in previous versions of redux-observable?
I think it has always been like this.
The text was updated successfully, but these errors were encountered:
Expected order:
reducer1(action1, state1),
reducer2(action1, state1),
epic1(action1, state1), // Dispatches action2, but waits for all epics to be called with current state/action
epic2(action1, state1),
Unexpected behavior when emitting actions synchronously
What is the current behavior?
When an epic dispatches an action synchronously, it will in turn synchronously call
store.dispatch
(https://github.com/redux-observable/redux-observable/blob/master/src/createEpicMiddleware.ts#L85). This means all reducers and epics will be called with the new action before the current action propagates through the remaining combined epics. This causes some confusion where thestate$.value
can differ from what would be expected (even inside the same state$ pipe).If the current behavior is a bug, please provide the steps to reproduce and a minimal demo of the problem using JSBin, StackBlitz, or similar.
What is the expected behavior?
I would expect the epics to dispatch actions after the current action/state has been passed to each epic in combine epics.
However I understand this has probably been around for a while, and may only crop up in more complex use cases (with multiple epics).
A workaround is to add
delay(1)
to the end of any epic that dispatches synchronously (specifically in response to an emit on state$ or action$).If this is unlikely to be fixed it may be good to have it added to a "known issues" section in the docs?
Which versions of redux-observable, and which browser and OS are affected by this issue? Did this work in previous versions of redux-observable?
I think it has always been like this.
The text was updated successfully, but these errors were encountered: