@@ -53,6 +53,9 @@ var VirtualList = function VirtualList(options) {
53
53
54
54
var _this = _possibleConstructorReturn ( this , ( vlist . __proto__ || Object . getPrototypeOf ( vlist ) ) . call ( this , props ) ) ;
55
55
56
+ _this . _isMounted = false ;
57
+
58
+
56
59
_this . options = _extends ( {
57
60
container : typeof window !== 'undefined' ? window : undefined
58
61
} , options ) ;
@@ -82,17 +85,25 @@ var VirtualList = function VirtualList(options) {
82
85
// get first and lastItemIndex
83
86
var state = ( 0 , _getVisibleItemBounds2 . default ) ( list , container , items , itemHeight , itemBuffer ) ;
84
87
88
+ if ( state === undefined ) {
89
+ return ;
90
+ }
91
+
85
92
if ( state . firstItemIndex > state . lastItemIndex ) {
86
93
return ;
87
94
}
88
95
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 ) {
90
97
this . setState ( state ) ;
91
98
}
92
99
}
93
100
} , {
94
101
key : 'refreshState' ,
95
102
value : function refreshState ( ) {
103
+ if ( ! this . _isMounted ) {
104
+ return ;
105
+ }
106
+
96
107
var _props = this . props ,
97
108
itemHeight = _props . itemHeight ,
98
109
items = _props . items ,
@@ -101,6 +112,11 @@ var VirtualList = function VirtualList(options) {
101
112
102
113
this . setStateIfNeeded ( this . domNode , this . options . container , items , itemHeight , itemBuffer ) ;
103
114
}
115
+ } , {
116
+ key : 'componentWillMount' ,
117
+ value : function componentWillMount ( ) {
118
+ this . _isMounted = true ;
119
+ }
104
120
} , {
105
121
key : 'componentDidMount' ,
106
122
value : function componentDidMount ( ) {
@@ -117,6 +133,8 @@ var VirtualList = function VirtualList(options) {
117
133
} , {
118
134
key : 'componentWillUnmount' ,
119
135
value : function componentWillUnmount ( ) {
136
+ this . _isMounted = false ;
137
+
120
138
// remove events
121
139
this . options . container . removeEventListener ( 'scroll' , this . refreshState ) ;
122
140
this . options . container . removeEventListener ( 'resize' , this . refreshState ) ;
0 commit comments