Skip to content

Commit

Permalink
fix: reduce frequency of iframe removed error (#429)
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarleonnogales committed Oct 30, 2023
1 parent 02bcaab commit fd2ec05
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/parent/parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ export function parentComponent<P, X, C>({
let childComponent: ?ChildExportsType<P>;
let currentChildDomain: ?string;
let currentContainer: HTMLElement | void;
let isRenderFinished: boolean = false;

const onErrorOverride: ?OnError = overrides.onError;
let getProxyContainerOverride: ?GetProxyContainer =
Expand Down Expand Up @@ -872,11 +873,23 @@ export function parentComponent<P, X, C>({
})
.then((isClosed) => {
if (!cancelled) {
if (isClosed) {
return close(new Error(`Detected ${context} close`));
} else {
return watchForClose(proxyWin, context);
if (context === CONTEXT.POPUP && isClosed) {
return close(new Error(COMPONENT_ERROR.POPUP_CLOSE));
}

const isCurrentContainerClosed: boolean = Boolean(
currentContainer && isElementClosed(currentContainer)
);

if (
context === CONTEXT.IFRAME &&
isClosed &&
(isCurrentContainerClosed || isRenderFinished)
) {
return close(new Error(COMPONENT_ERROR.IFRAME_CLOSE));
}

return watchForClose(proxyWin, context);
}
});
};
Expand Down Expand Up @@ -1628,6 +1641,7 @@ export function parentComponent<P, X, C>({
});

const onRenderedPromise = initPromise.then(() => {
isRenderFinished = true;
return event.trigger(EVENT.RENDERED);
});

Expand Down

0 comments on commit fd2ec05

Please sign in to comment.