From 53432775742a56aad8377c84258ec8d7a17d0450 Mon Sep 17 00:00:00 2001 From: Oscar Leon <63573634+oscarleonnogales@users.noreply.github.com> Date: Mon, 1 May 2023 14:04:35 -0600 Subject: [PATCH] fix: reduce frequency of "Detected iframe close" error (#426) Avoid throwing the "Detected iframe close" error when the component is removed from the DOM during the prerender phase. --- src/parent/parent.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/parent/parent.js b/src/parent/parent.js index bd92ad29..830ac1ed 100644 --- a/src/parent/parent.js +++ b/src/parent/parent.js @@ -317,6 +317,7 @@ export function parentComponent
({ let childComponent: ?ChildExportsType
; let currentChildDomain: ?string; let currentContainer: HTMLElement | void; + let isRenderFinished: boolean = false; const onErrorOverride: ?OnError = overrides.onError; let getProxyContainerOverride: ?GetProxyContainer = @@ -862,11 +863,23 @@ export function parentComponent
({ }) .then((isClosed) => { if (!cancelled) { - if (isClosed) { - return close(new Error(`Detected ${context} close`)); - } else { - return watchForClose(proxyWin, context); + const isCurrentContainerClosed: boolean = Boolean( + currentContainer && isElementClosed(currentContainer) + ); + + if (context === CONTEXT.POPUP && isClosed) { + return close(new Error(COMPONENT_ERROR.POPUP_CLOSE)); + } + + if ( + context === CONTEXT.IFRAME && + isClosed && + (isCurrentContainerClosed || isRenderFinished) + ) { + return close(new Error(COMPONENT_ERROR.IFRAME_CLOSE)); } + + return watchForClose(proxyWin, context); } }); }; @@ -1618,6 +1631,7 @@ export function parentComponent
({ }); const onRenderedPromise = initPromise.then(() => { + isRenderFinished = true; return event.trigger(EVENT.RENDERED); });