@@ -136,7 +136,7 @@ export class Fetch extends React.Component {
136136 // When a request is already in flight, and a new one is
137137 // configured, then we need to "cancel" the previous one.
138138 cancelExistingRequest = reason => {
139- if ( this . state . fetching && ! this . hasHandledNetworkResponse ) {
139+ if ( this . state . fetching && this . _currentRequestKey !== null ) {
140140 const abortError = new Error ( reason ) ;
141141 // This is an effort to mimic the error that is created when a
142142 // fetch is actually aborted using the AbortController API.
@@ -214,6 +214,8 @@ export class Fetch extends React.Component {
214214 const requestKey = this . getRequestKey ( options ) ;
215215 const requestOptions = Object . assign ( { } , this . props , options ) ;
216216
217+ this . _currentRequestKey = requestKey ;
218+
217219 const {
218220 url,
219221 body,
@@ -261,8 +263,6 @@ export class Fetch extends React.Component {
261263 // cancel the in-flight request.
262264 this . responseReceivedInfo = responseReceivedInfo ;
263265
264- this . hasHandledNetworkResponse = false ;
265-
266266 const fetchPolicy = this . getFetchPolicy ( ) ;
267267
268268 let cachedResponse ;
@@ -315,7 +315,7 @@ export class Fetch extends React.Component {
315315 responseCache [ requestKey ] = res ;
316316 }
317317
318- if ( ! this . hasHandledNetworkResponse ) {
318+ if ( this . _currentRequestKey === requestKey ) {
319319 this . onResponseReceived ( {
320320 ...responseReceivedInfo ,
321321 response : res ,
@@ -327,7 +327,7 @@ export class Fetch extends React.Component {
327327 return res ;
328328 } ,
329329 error => {
330- if ( ! this . hasHandledNetworkResponse ) {
330+ if ( this . _currentRequestKey === requestKey ) {
331331 this . onResponseReceived ( {
332332 ...responseReceivedInfo ,
333333 error,
@@ -358,7 +358,7 @@ export class Fetch extends React.Component {
358358 this . responseReceivedInfo = null ;
359359
360360 if ( ! stillFetching ) {
361- this . hasHandledNetworkResponse = true ;
361+ this . _currentRequestKey = null ;
362362 }
363363
364364 let data ;
0 commit comments