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
It looks like every INIT_COMPONENT causes all withInitAction's connect to execute and cause re-renders.
I'm not 100% sure, but it looks like the following is happening:
When INIT_COMPONENT fires from any component, the selfInit in the reducer is updated where completed is updated for the prepareHash for that component:
Because of 3), the withInitAction component will cause a re-render itself.
Most of the time when withInitAction is used to get some data, the same component is also wrapped into a connect to get the info from the state. The connect will not 'block' the re-render of the wrapped component, since it will only do purity checks on the output of it's own mapStateToProps.
And because of 4) The wrapped component will also be re-rendered. In this case, making it a PureComponent will halt the re-render, because the render in 4) didn't pass any new/updated props.
Possible fix;
improve the selector from 2) to better deal with state updates that are not relevant for that component, or
add a custom equality check for the withInitAction connect to battle the failing selector, or
implement a shouldComponentUpdate in the withInitAction component as a last resort.
Example:
If we have a tree of 50 components that have a withInitAction, and all of them will start and complete (two actions per component), all 50 components will re-render on all of the 100 actions, causing a lot of usless code execution.
The text was updated successfully, but these errors were encountered:
It looks like every
INIT_COMPONENT
causes allwithInitAction
'sconnect
to execute and cause re-renders.I'm not 100% sure, but it looks like the following is happening:
When
INIT_COMPONENT
fires from any component, theselfInit
in the reducer is updated wherecompleted
is updated for theprepareHash
for that component:react-redux-component-init/src/reducer.js
Lines 36 to 39 in e9341fd
When that happens, the 2nd param in the selector will 'break' the memoization:
react-redux-component-init/src/reducer.js
Line 57 in e9341fd
This will cause the
connect
inwithInitAction
to return a new object for__componentInitState
:react-redux-component-init/src/withInitAction.js
Lines 200 to 205 in e9341fd
Because of 3), the withInitAction component will cause a re-render itself.
Most of the time when
withInitAction
is used to get some data, the same component is also wrapped into aconnect
to get the info from the state. The connect will not 'block' the re-render of the wrapped component, since it will only do purity checks on the output of it's own mapStateToProps.And because of 4) The wrapped component will also be re-rendered. In this case, making it a
PureComponent
will halt the re-render, because the render in 4) didn't pass any new/updated props.Possible fix;
Example:
If we have a tree of 50 components that have a withInitAction, and all of them will start and complete (two actions per component), all 50 components will re-render on all of the 100 actions, causing a lot of usless code execution.
The text was updated successfully, but these errors were encountered: