@@ -34,15 +34,15 @@ const PASSIVE = (() => {
3434} ) ( ) ? { passive : true } : false ;
3535
3636const UNSTABLE_MESSAGE = 'ReactList failed to reach a stable state.' ;
37+ const MARKER_DURATION = 100 ;
38+ const MAX_UPDATES_PER_MARKER_DURATION = 20 ;
3739
3840const isEqualSubset = ( a , b ) => {
3941 for ( let key in b ) if ( a [ key ] !== b [ key ] ) return false ;
4042
4143 return true ;
4244} ;
4345
44- const isEqual = ( a , b ) => isEqualSubset ( a , b ) && isEqualSubset ( b , a ) ;
45-
4646module . exports = class ReactList extends Component {
4747 static displayName = 'ReactList' ;
4848
@@ -97,31 +97,28 @@ module.exports = class ReactList extends Component {
9797 this . updateFrame ( this . scrollTo . bind ( this , this . props . initialIndex ) ) ;
9898 }
9999
100- componentDidUpdate ( prevProps , prevState ) {
100+ componentDidUpdate ( ) {
101101
102102 // If the list has reached an unstable state, prevent an infinite loop.
103103 if ( this . unstable ) return ;
104104
105- // Update calculations if props have changed between renders.
106- const propsEqual = isEqual ( this . props , prevProps ) ;
107- if ( ! propsEqual ) {
108- this . prevPrevState = { } ;
109- return this . updateFrame ( ) ;
105+ if ( this . updateMarker && Date . now ( ) - this . updateMarker > MARKER_DURATION ) {
106+ delete this . updateMarker ;
107+ }
108+
109+ if ( ! this . updateMarker ) {
110+ this . updateMarker = Date . now ( ) ;
111+ this . updatesSinceMarker = 0 ;
110112 }
111113
112- // Check for ping-ponging between the same two states.
113- const stateEqual = isEqual ( this . state , prevState ) ;
114- const pingPong = ! stateEqual && isEqual ( this . state , this . prevPrevState ) ;
114+ ++ this . updatesSinceMarker ;
115115
116- // Ping-ponging between states means this list is unstable, log an error.
117- if ( pingPong ) {
116+ if ( this . updatesSinceMarker > MAX_UPDATES_PER_MARKER_DURATION ) {
118117 this . unstable = true ;
119118 return console . error ( UNSTABLE_MESSAGE ) ;
120119 }
121120
122- // Update calculations if state has changed between renders.
123- this . prevPrevState = prevState ;
124- if ( ! stateEqual ) this . updateFrame ( ) ;
121+ this . updateFrame ( ) ;
125122 }
126123
127124 maybeSetState ( b , cb ) {
0 commit comments