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
{{ message }}
Repository navigation
Infinite loop of the 'componentDidUpdate' method (caused by an infinite state update). #250
I've tried to render a list with a multiple items (of fixed size) per row, but it always prints 'ReactList failed to reach a stable state' in the console and slowdown the rendering. I've tried with both flex-box and inline-block, but no success. For e.g. the following fails:
changed the title [-]Multiple elements per row ('uniform' type), doesn't works.[/-][+]Multiple elements per row ('uniform' type), doesn't work.[/+]on Oct 3, 2022
Ok, looking at the source, the issue is the following:
the componentDidUpdate invokes the updateFrame. That method invokes maybeSetState that updates the component's state (if the state is changed). When the state of a component is updated, the componentDidUpdate is invoked again. You might think that in such new call of componentDidUpdate, the maybeSetState doesn't update the state anymore but debugging the maybeSetState, I've seen that the state is not updated and so the code changes it again leading to an infinite loop (this behavious is strange because in theory React should guarantee that the state is updated before invoking componentDidUpdate). I use React 18.2.0. This happens always when I scroll down the list and I reach the last element on the bottom.
changed the title [-]Multiple elements per row ('uniform' type), doesn't work.[/-][+]Infinite loop of the 'componentDidUpdate' method (caused by an infinite state update).[/+]on Oct 3, 2022
Activity
[-]Multiple elements per row ('uniform' type), doesn't works.[/-][+]Multiple elements per row ('uniform' type), doesn't work.[/+]Gianarci commentedon Oct 3, 2022
Ok, looking at the source, the issue is the following:
the
componentDidUpdateinvokes theupdateFrame. That method invokesmaybeSetStatethat updates the component's state (if the state is changed). When the state of a component is updated, thecomponentDidUpdateis invoked again. You might think that in such new call ofcomponentDidUpdate, themaybeSetStatedoesn't update the state anymore but debugging themaybeSetState, I've seen that the state is not updated and so the code changes it again leading to an infinite loop (this behavious is strange because in theory React should guarantee that the state is updated before invokingcomponentDidUpdate). I use React 18.2.0. This happens always when I scroll down the list and I reach the last element on the bottom.[-]Multiple elements per row ('uniform' type), doesn't work.[/-][+]Infinite loop of the 'componentDidUpdate' method (caused by an infinite state update).[/+]