Skip to content

Commit

Permalink
fix: resolve the promise when component is closed/destroyed (#455)
Browse files Browse the repository at this point in the history
* fix: resolve the promise when component is closed/destroyed

* fix: separate detected close errors to reject promise case
  • Loading branch information
siddy2181 authored Jun 4, 2024
1 parent e4da223 commit b42cc03
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const COMPONENT_ERROR = {
COMPONENT_DESTROYED: "Component destroyed",
COMPONENT_CLOSED: "Component closed",
WINDOW_CLOSED: "Detected component window close",
POPUP_CLOSE: "Detected popup close",
IFRAME_CLOSE: "Detected iframe close",
};

Expand Down
5 changes: 3 additions & 2 deletions src/parent/parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,8 @@ export function parentComponent<P, X, C>({
const error = err || new Error(COMPONENT_ERROR.COMPONENT_DESTROYED);
if (
(currentContainer && isElementClosed(currentContainer)) ||
error.message === COMPONENT_ERROR.NAVIGATED_AWAY
// $FlowFixMe
Object.values(COMPONENT_ERROR).includes(error.message)
) {
initPromise.resolve();
} else {
Expand Down Expand Up @@ -883,7 +884,7 @@ export function parentComponent<P, X, C>({
.then((isClosed) => {
if (!cancelled) {
if (context === CONTEXT.POPUP && isClosed) {
return close(new Error(COMPONENT_ERROR.POPUP_CLOSE));
return close(new Error("Detected popup close"));
}

const isCurrentContainerClosed: boolean = Boolean(
Expand Down

0 comments on commit b42cc03

Please sign in to comment.