@@ -157,62 +157,61 @@ export const WithChallengeTaskClusters = function (
157157 ignoreLocked ,
158158 )
159159 . then ( ( results ) => {
160- if ( currentFetchId >= this . state . fetchId ) {
161- const totalCount = results . length ;
162- // If we retrieved 1001 tasks then there might be more tasks and
163- // they should be clustered. So fetch as clusters
164- // (unless we are zoomed all the way in already)
165- if ( totalCount > UNCLUSTER_THRESHOLD && ( this . props . criteria ?. zoom ?? 0 ) < MAX_ZOOM ) {
166- this . props
167- . fetchTaskClusters ( challengeId , searchCriteria , 25 , overrideDisable )
168- . then ( ( results ) => {
169- const clusters = results . clusters ;
170- if ( currentFetchId >= this . state . fetchId ) {
171- const taskCount = _sum ( _map ( clusters , ( c ) => c . numberOfPoints ) ) ;
172- this . setState ( {
173- clusters,
174- loading : false ,
175- taskCount : taskCount ,
176- showAsClusters : true ,
177- } ) ;
178- }
160+ if ( ! this . _isMounted || currentFetchId < this . state . fetchId ) return ;
161+ const totalCount = results . length ;
162+ // If we retrieved 1001 tasks then there might be more tasks and
163+ // they should be clustered. So fetch as clusters
164+ // (unless we are zoomed all the way in already)
165+ if ( totalCount > UNCLUSTER_THRESHOLD && ( this . props . criteria ?. zoom ?? 0 ) < MAX_ZOOM ) {
166+ this . props
167+ . fetchTaskClusters ( challengeId , searchCriteria , 25 , overrideDisable )
168+ . then ( ( results ) => {
169+ if ( ! this . _isMounted || currentFetchId < this . state . fetchId ) return ;
170+ const clusters = results . clusters ;
171+ const taskCount = _sum ( _map ( clusters , ( c ) => c . numberOfPoints ) ) ;
172+ this . setState ( {
173+ clusters,
174+ loading : false ,
175+ taskCount : taskCount ,
176+ showAsClusters : true ,
179177 } ) ;
180- } else {
181- this . setState ( {
182- clusters : results ,
183- loading : false ,
184- taskCount : totalCount ,
185178 } ) ;
186- }
179+ } else {
180+ this . setState ( {
181+ clusters : results ,
182+ loading : false ,
183+ taskCount : totalCount ,
184+ } ) ;
187185 }
188186 } )
189187 . catch ( ( error ) => {
190188 console . log ( error ) ;
191- this . setState ( { clusters : { } , loading : false , taskCount : 0 } ) ;
189+ if ( this . _isMounted ) this . setState ( { clusters : { } , loading : false , taskCount : 0 } ) ;
192190 } ) ;
193191 } else {
194192 this . props
195193 . fetchTaskClusters ( challengeId , searchCriteria , 25 , overrideDisable )
196194 . then ( ( results ) => {
195+ if ( ! this . _isMounted || currentFetchId < this . state . fetchId ) return ;
197196 const clusters = results . clusters ;
198- if ( currentFetchId >= this . state . fetchId ) {
199- const taskCount = _sum ( _map ( clusters , ( c ) => c . numberOfPoints ) ) ;
197+ const taskCount = _sum ( _map ( clusters , ( c ) => c . numberOfPoints ) ) ;
198+ this . setState ( {
199+ clusters,
200+ loading : false ,
201+ taskCount : taskCount ,
202+ showAsClusters : true ,
203+ } ) ;
204+ } )
205+ . catch ( ( error ) => {
206+ console . log ( error ) ;
207+ if ( this . _isMounted ) {
200208 this . setState ( {
201- clusters,
209+ clusters : { } ,
202210 loading : false ,
203- taskCount : taskCount ,
211+ taskCount : 0 ,
204212 showAsClusters : true ,
205213 } ) ;
206214 }
207- } )
208- . catch ( ( error ) => {
209- console . log ( error ) ;
210- this . setState ( {
211- clusters : { } ,
212- loading : false ,
213- taskCount : 0 ,
214- showAsClusters : true ,
215- } ) ;
216215 } ) ;
217216 }
218217 }
@@ -278,6 +277,7 @@ export const WithChallengeTaskClusters = function (
278277 } ;
279278
280279 updateTaskInClusters = async ( updatedTasks ) => {
280+ if ( ! this . _isMounted ) return ;
281281 if ( ! Array . isArray ( updatedTasks ) ) {
282282 updatedTasks = [ updatedTasks ] ;
283283 }
0 commit comments