-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
mapStateToProps is called when component is not due to render when a dispatch is triggered from componentDidUpdate #1397
Comments
Thanks for filing this. Hmm. It may very well be an unavoidable aspect of how the current implementation works, but I'd have to spend time to examine the exact timing sequence of React effects vs subscription callback execution to figure that out. To be honest, that's a very low priority for me atm. If you could do that, it would probably help me think through what's going on. |
Related to #1396? |
The sequence of events is
In v6.0.1 the order is
The fact that item.mapState and item.render is not called immediately on the first render before the lifecycle method is kinda unexpected. I think the problem may be that useLayoutEffect() is triggered after componentDidUpdate is resolved rather than immediately on render? |
6.0.1 isn't the correct version to be using here. It has known issues that led to us abandoning its approach entirely. You should be on 7.x, as it's built on Hooks and doesn't have the same quirks or performance issues. |
@timdorr : the sandbox is on v7, and the point being made is that v6 and v7 are behaving differently. @ykagan : There are definitely differences in internal implementation in v6 and v7 that lead to different timing of behaviors. I documented a lot of that in my post The History and Implementation of React-Redux. Also, I'm not entirely clear on what you mean by " |
Yes, each of those connect calls refers to mapState function calls. What I meant is that we're seemingly rendering the children in the first dispatch but the child render function doesn't get called but instead gets queued up behind the next dispatch and re-render. The problem we have is that we can then no longer assume that the child's mapState function gets called with valid state (eg: we can no longer assume it's rendered top-down like we could with v5 and v6). I see in that blog post you mentioned the "zombie child" issue - is that issue specific only to using hooks or is it generic to any use of v7? |
If that's not happening here, then there's an edge case that's slipping through the cracks. |
Kinda? Here's a slightly more clear example with the invariant removed: https://codesandbox.io/embed/react-redux-issue-debug-rvr-8whlb
the child render function is never called but mapState is, and it's called out of order. its a bit ambiguous whether this is a "zombie" since it never gets rendered, but it makes writing logic in mapState difficult. |
The issue is not because of top-down update. This can be verified by overriding the top-down update by providing When run with version In |
I there a workaround for this? |
Any updates? Having the same issue. |
I'm going to close this as a WONTFIX for now, largely because we're encouraging folks to stop using If someone still feels strongly about this please comment, or even better file a PR to improve behavior here. |
My workaround when encountering this kind of issue is wrapping my dispatches with |
When a dispatch is triggered from a lifecycle method as a side-effect of a re-render from a previous dispatch, we wind up calling mapStateToProps on components that are never going to be rendered and are about to be unmounted.
#1263 fixed a very similar issue when multiple dispatches are triggered simultaneously.
Minimal repro is here: https://codesandbox.io/embed/react-redux-issue-debug-rvr-8whlb
The text was updated successfully, but these errors were encountered: