From f379442b014e9fea7543070b9c5221fd3edbbf2b Mon Sep 17 00:00:00 2001 From: Rex Feng Date: Fri, 31 May 2024 10:53:24 -0700 Subject: [PATCH] when `this.stats` is called, add optional chaining or check for existence (#6459) --- src/utils/xhr-loader.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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);