File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -159,10 +159,13 @@ function createLoadableComponent(loadFn, options) {
159159 }
160160
161161 componentWillMount ( ) {
162- this . _mounted = true ;
163162 this . _loadModule ( ) ;
164163 }
165164
165+ componentDidMount ( ) {
166+ this . _mounted = true ;
167+ }
168+
166169 _loadModule ( ) {
167170 if ( this . context . loadable && Array . isArray ( opts . modules ) ) {
168171 opts . modules . forEach ( moduleName => {
@@ -174,28 +177,32 @@ function createLoadableComponent(loadFn, options) {
174177 return ;
175178 }
176179
177- if ( typeof opts . delay === "number" ) {
180+ let setStateWithMountCheck = ( newState ) => {
181+ if ( ! this . _mounted ) {
182+ return ;
183+ }
184+
185+ this . setState ( newState ) ;
186+ }
187+
188+ if ( typeof opts . delay === 'number' ) {
178189 if ( opts . delay === 0 ) {
179190 this . setState ( { pastDelay : true } ) ;
180191 } else {
181192 this . _delay = setTimeout ( ( ) => {
182- this . setState ( { pastDelay : true } ) ;
193+ setStateWithMountCheck ( { pastDelay : true } ) ;
183194 } , opts . delay ) ;
184195 }
185196 }
186197
187198 if ( typeof opts . timeout === "number" ) {
188199 this . _timeout = setTimeout ( ( ) => {
189- this . setState ( { timedOut : true } ) ;
200+ setStateWithMountCheck ( { timedOut : true } ) ;
190201 } , opts . timeout ) ;
191202 }
192203
193204 let update = ( ) => {
194- if ( ! this . _mounted ) {
195- return ;
196- }
197-
198- this . setState ( {
205+ setStateWithMountCheck ( {
199206 error : res . error ,
200207 loaded : res . loaded ,
201208 loading : res . loading
You can’t perform that action at this time.
0 commit comments