diff --git a/src/utils/xhr-loader.ts b/src/utils/xhr-loader.ts index 7160a23013a..d6155cc622a 100644 --- a/src/utils/xhr-loader.ts +++ b/src/utils/xhr-loader.ts @@ -40,8 +40,6 @@ class XhrLoader implements Loader { this.config = null; this.context = null; this.xhrSetup = null; - // @ts-ignore - this.stats = null; } abortInternal() { @@ -100,15 +98,16 @@ class XhrLoader implements Loader { if (xhrSetup) { Promise.resolve() .then(() => { - if (this.stats.aborted) return; + if (this.loader !== xhr || this.stats.aborted) return; return xhrSetup(xhr, context.url); }) .catch((error: Error) => { + if (this.loader !== xhr || this.stats.aborted) return; xhr.open('GET', context.url, true); return xhrSetup(xhr, context.url); }) .then(() => { - if (this.stats.aborted) return; + if (this.loader !== xhr || this.stats.aborted) return; this.openAndSendXhr(xhr, context, config); }) .catch((error: Error) => { @@ -263,7 +262,8 @@ class XhrLoader implements Loader { } loadtimeout() { - const retryConfig = this.config?.loadPolicy.timeoutRetry; + if (!this.config) return; + const retryConfig = this.config.loadPolicy.timeoutRetry; const retryCount = this.stats.retry; if (shouldRetry(retryConfig, retryCount, true)) { this.retry(retryConfig);