@@ -53,6 +53,9 @@ var VirtualList = function VirtualList(options) {
5353
5454 var _this = _possibleConstructorReturn ( this , ( vlist . __proto__ || Object . getPrototypeOf ( vlist ) ) . call ( this , props ) ) ;
5555
56+ _this . _isMounted = false ;
57+
58+
5659 _this . options = _extends ( {
5760 container : typeof window !== 'undefined' ? window : undefined
5861 } , options ) ;
@@ -82,17 +85,25 @@ var VirtualList = function VirtualList(options) {
8285 // get first and lastItemIndex
8386 var state = ( 0 , _getVisibleItemBounds2 . default ) ( list , container , items , itemHeight , itemBuffer ) ;
8487
88+ if ( state === undefined ) {
89+ return ;
90+ }
91+
8592 if ( state . firstItemIndex > state . lastItemIndex ) {
8693 return ;
8794 }
8895
89- if ( state !== undefined && ( state . firstItemIndex !== this . state . firstItemIndex || state . lastItemIndex !== this . state . lastItemIndex ) ) {
96+ if ( state . firstItemIndex !== this . state . firstItemIndex || state . lastItemIndex !== this . state . lastItemIndex ) {
9097 this . setState ( state ) ;
9198 }
9299 }
93100 } , {
94101 key : 'refreshState' ,
95102 value : function refreshState ( ) {
103+ if ( ! this . _isMounted ) {
104+ return ;
105+ }
106+
96107 var _props = this . props ,
97108 itemHeight = _props . itemHeight ,
98109 items = _props . items ,
@@ -101,6 +112,11 @@ var VirtualList = function VirtualList(options) {
101112
102113 this . setStateIfNeeded ( this . domNode , this . options . container , items , itemHeight , itemBuffer ) ;
103114 }
115+ } , {
116+ key : 'componentWillMount' ,
117+ value : function componentWillMount ( ) {
118+ this . _isMounted = true ;
119+ }
104120 } , {
105121 key : 'componentDidMount' ,
106122 value : function componentDidMount ( ) {
@@ -117,6 +133,8 @@ var VirtualList = function VirtualList(options) {
117133 } , {
118134 key : 'componentWillUnmount' ,
119135 value : function componentWillUnmount ( ) {
136+ this . _isMounted = false ;
137+
120138 // remove events
121139 this . options . container . removeEventListener ( 'scroll' , this . refreshState ) ;
122140 this . options . container . removeEventListener ( 'resize' , this . refreshState ) ;
0 commit comments