From 95e42bc0963432e8e750897da501cea9a5fb4540 Mon Sep 17 00:00:00 2001 From: Popov Aleksey Date: Mon, 11 Sep 2023 23:59:56 -0700 Subject: [PATCH] refactor: removed IE leftovers from src\client\core\barriers (#7997) ## Purpose _Describe the problem you want to address or the feature you want to implement._ ## Approach _Describe how your changes address the issue or implement the desired functionality in as much detail as possible._ ## References _Provide a link to the existing issue(s), if any._ ## Pre-Merge TODO - [ ] Write tests for your proposed changes - [ ] Make sure that existing tests do not fail --- .../core/barriers/page-unload-barrier.ts | 71 ++++--------------- 1 file changed, 13 insertions(+), 58 deletions(-) diff --git a/src/client/core/barriers/page-unload-barrier.ts b/src/client/core/barriers/page-unload-barrier.ts index 915df310562..1e17c540acb 100644 --- a/src/client/core/barriers/page-unload-barrier.ts +++ b/src/client/core/barriers/page-unload-barrier.ts @@ -2,18 +2,14 @@ import hammerhead from '../deps/hammerhead'; import * as eventUtils from '../utils/event'; import delay from '../utils/delay'; import MESSAGE from '../../../test-run/client-messages'; -import { isAnchorElement } from '../utils/dom'; -const Promise = hammerhead.Promise; -const browserUtils = hammerhead.utils.browser; -const nativeMethods = hammerhead.nativeMethods; -const transport = hammerhead.transport; +const Promise = hammerhead.Promise; +const transport = hammerhead.transport; -const DEFAULT_BARRIER_TIMEOUT = 400; -const SHORT_WAIT_FOR_UNLOAD_TIMEOUT = 30; -const FILE_DOWNLOAD_CHECK_DELAY = 500; -const MAX_UNLOADING_TIMEOUT = 15_000; +const DEFAULT_BARRIER_TIMEOUT = 400; +const FILE_DOWNLOAD_CHECK_DELAY = 500; +const MAX_UNLOADING_TIMEOUT = 15_000; let unloading = false; @@ -22,48 +18,9 @@ let pageNavigationTriggeredListener = null as (() => void) | null; let pageNavigationTriggered = false; function onBeforeUnload (): void { - if (browserUtils.isIE) { - prolongUnloadWaitingIeOnly(SHORT_WAIT_FOR_UNLOAD_TIMEOUT); - exceptFileDownloadingIeOnly(); - - return; - } - unloading = true; } -// NOTE: this variables are for IE only -let waitingForUnload = false; -let waitingForUnloadTimeoutId = null as (() => void) | null; -let waitingPromiseResolvers = [] as (() => void)[]; - -function prolongUnloadWaitingIeOnly (timeout: number): void { - if (waitingForUnloadTimeoutId) - nativeMethods.clearTimeout.call(window, waitingForUnloadTimeoutId); - - waitingForUnload = true; - - waitingForUnloadTimeoutId = nativeMethods.setTimeout.call(window, () => { - waitingForUnloadTimeoutId = null; - waitingForUnload = false; - - waitingPromiseResolvers.forEach(resolve => resolve()); - waitingPromiseResolvers = []; - }, timeout); -} - -function exceptFileDownloadingIeOnly (): void { - delay(0) - .then(() => { - // NOTE: except file downloading - if (document.readyState === 'loading') { - const activeElement = nativeMethods.documentActiveElementGetter.call(document); - - if (!activeElement || !isAnchorElement(activeElement) || !activeElement.hasAttribute('download')) - unloading = true; - } - }); -} function waitForFileDownload (): Promise { return delay(FILE_DOWNLOAD_CHECK_DELAY) @@ -104,17 +61,15 @@ export function wait (timeout?: number): Promise { } const waitForUnloadingPromise = delay(timeout) - // eslint-disable-next-line consistent-return .then((): void | Promise => { - if (unloading) { - return waitForFileDownload() - .then(() => { - unloading = false; - }); - } - - if (waitingForUnload) - return new Promise((resolve: () => void) => waitingPromiseResolvers.push(resolve)); + if (!unloading) + return void 0; + + return waitForFileDownload() + .then(() => { + unloading = false; + }); + }); // NOTE: sometimes the page isn't actually unloaded after the beforeunload event