From b42cc038ec0019165848aa95ebffa652960e61d7 Mon Sep 17 00:00:00 2001 From: Shraddha <24843989+siddy2181@users.noreply.github.com> Date: Tue, 4 Jun 2024 06:40:59 -0700 Subject: [PATCH] fix: resolve the promise when component is closed/destroyed (#455) * fix: resolve the promise when component is closed/destroyed * fix: separate detected close errors to reject promise case --- src/constants.js | 1 - src/parent/parent.js | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/constants.js b/src/constants.js index 77394658..9a1b0e46 100644 --- a/src/constants.js +++ b/src/constants.js @@ -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", }; diff --git a/src/parent/parent.js b/src/parent/parent.js index d3798d53..070c8f9c 100644 --- a/src/parent/parent.js +++ b/src/parent/parent.js @@ -753,7 +753,8 @@ export function parentComponent
({ 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 { @@ -883,7 +884,7 @@ export function parentComponent
({ .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(