-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: "Reducers may not dispatch actions" #2753
Comments
Is one of your reducers asynchronous in some way? If so, that is considered a side effect. You should push any side effects to be handled in your middleware, not your reducer functions. They should be pure (no global variable access, including setTimeout). |
@timdorr the reducers are all pure synchronous functions |
@timdorr This question seems to have been closed prematurely. |
This is a bug tracker, not a support system. For usage questions, please use Stack Overflow or Reactiflux where there are a lot more people ready to help you out. Thanks! |
@cjpete interestingly I just found the same exact error pop up in my sentry logs. I use The reducers are small, straightforward, and include no asynchronous code in them such as They were using Chrome 63.0.3239 on Windows 8.1. If I figure out a way to reproduce it I will surely post back here. But I thought you'd be happy to know you are not the only one. |
Also started seeing some of these errors show up in sentry (IE11, Windows). We have a custom promise based request middleware w/ redux-thunk, all reducers are pure functions. I wonder if there is any connection with reduxjs/redux-thunk#122. |
This admittedly seems to be "impossible". I would really appreciate it if someone could manage to come up with a repro of some kind. |
I'm also seeing this |
it's happening to me too (in react native), and it's crashing the app... and likewise, none of my reducers are dispatching actions, and all are synchronous
|
some news about this ? I have the same problem. export function fetchDashboard() {
return (dispatch) => {
dispatch(isFetching()); // Error
};
} "react": "16.2.0",
"react-native": "0.52.0",
"react-redux": "5.0.5",
"redux": "3.7.2",
"redux-thunk": "2.2.0" For now this is the solution: |
I agree this should be impossible. However I managed to recreate this using Chrome 75.0.3770.100. I'm trying to get this to happen again but I haven't managed to get it to happen again. But I would be interested if someone else can get it to happen again. I burrowed the prime number functions from
Running
|
But this has been driving me nuts. If the redux store ever get into this state it cannot recover. Contemplating forking off my own version to unset isDispatching when this error occurs, which I don't think we should have to do but it's better then the app breaking because of it. |
To be blunt: if there's an issue here, it's not the fault of Redux. The logic is sound - there's nothing we can do about environments that might be somehow doing something bizarre. |
I know that, firefox is fine as far as I have tested it, and this should be impossible with javascript running as a single thread. But letting people know should they randomly experience this issue, as I can't find much about this issue online. Also confirming that this is not a redux issue, but this issue will break it when it occurs. |
Yea, I mean this issue has been closed since it was created. I never really expected anything to be done about this. I don’t believe the issue is in the redux source or our source at all. It is good to collect what information we do have on the subject to see if we could find the true cause, but it is a difficult one. In the case above, if you are able to reproduce a problem with JS execution order perhaps this discussion should be moved to a ticket here? Perhaps they will tell us this is a possibility due to some extreme circumstance we haven’t thought up. |
Yeah my search still goes on to isolate the exact cause, it is really driving me nuts. Thinking about this some more, it seems the current execution just completely stops silently, and so it never progresses to the finally statement, if it did it would eventually recover, but it does not. Thanks for the link, I'll see if anyone has reported this issue, if not I'll continue trying to isolate it to reproducible steps and report it myself. |
I haven't been able to replicate this in an isolated environment, but it's an error which keeps getting picked up from our error reporter.
We have two websockets which asynchronously push data to the client. Upon receiving messages on these websockets, redux store actions are dispatched.
What appears to be happening based on our error stack trace is that mid-way between one state update cycle occurring (perhaps in between reducer function calls) an asynchronous message is being received on one of the sockets, and this somehow is prioritised above the current redux state update cycle - thus when it gets to the end of the cycle it sees that an action has been dispatched in that time, and throws the error.
Stack trace from error capture:
As you can see there are two calls to "src/api/asyncListeners -> listener" - these are both reactions to asynchronous events, and are not related / triggered by each other.
Below is an example fiddle which doesn't show the problem. Clearly this code waits for the first state update cycle to run before processing the next action:
https://jsfiddle.net/pojzf7vx/2/
TL;DR;
When the "Reducers may not dispatch actions" error is thrown, is this because something is likely to have gone wrong in the redux store? Or is this a best practice warning to prevent, say, infinite loops?
Will redux start a secondary state update cycle if it receives an action mid-update?
Is there any way to force redux to process full state updates for actions one at a time?
Appreciate any help/advice!
The text was updated successfully, but these errors were encountered: