mapStateToProps called when component not due to render
See original GitHub issueHi,
I have a conditionally displayed component, based on a value in redux. All components below are connect
ed.
eg in a wrapper component’s render method:
{ (showValueInRedux) ? <ComponentUsingShowValue/> : <EmptyComponent/> }
ComponentUsingShowValue
has a mapStateToProps
that uses redux state that it expects to be there, hence we guard for that with showValueInRedux
in the wrapper component.
In version 6, mapStateToProps
in ComponentUsingShowValue
is only called when that component is due to render.
In version 7, mapStateToProps
is called even if the wrapping component has switched to choosing EmptyComponent
due to showValueInRedux
being false (after having once been true).
This causes an exception in our current code because the redux values that mapStateToProps
uses ( in the now non-rendered component) are not available.
Please could you clarify this change in behaviour?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:24 (17 by maintainers)
I have further minimized the sandbox and the problem seems clear now: in certain situations two dispatches just after another will lead to
checkForUpdates
(the store subscription callback) being called twice after another. If the result of the second call doesn’t change, it will immediately triggernotifyNestedSubs
. This causes the issue. I will spend some time later today or tomorrow to turn this into a test case and then hopefully come up with a fix (though I don’t really have an idea right now how this could be fixed).I made the sandbox much smaller, so that it is easier to analyze. I need to go to sleep now, and I will only be able to continue on Friday, but maybe somebody else can solve this. Based on my reduced example the issue can only be due to either the timing of the async fetch action in the select inbox thunk or due to a state update occuring inside
componentDidUpdate
inInboxView
.