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); });