Skip to content

Commit

Permalink
fix: reduce frequency of "Detected iframe close" error (#426)
Browse files Browse the repository at this point in the history
Avoid throwing the "Detected iframe close" error when the
component is removed from the DOM during the prerender phase.
  • Loading branch information
oscarleonnogales authored May 1, 2023
1 parent ed6e6dc commit 5343277
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 @@ -862,11 +863,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);
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);
}
});
};
Expand Down Expand Up @@ -1618,6 +1631,7 @@ export function parentComponent<P, X, C>({
});

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

Expand Down

0 comments on commit 5343277

Please sign in to comment.