From 52e99f904e17f52366c2eecb555067ee7c747aa7 Mon Sep 17 00:00:00 2001 From: Ronald Langeveld Date: Tue, 23 Jan 2024 12:31:08 +0000 Subject: [PATCH] Added Portal Frame conditions (#19549) no issue - adds 2 addition conditions for when the Portal iframe should be visible. - waits an extra 100ms before making it visible to give portal time to properly load. --------- Co-authored-by: Princi Vershwal --- .../membership/portal/PortalFrame.tsx | 19 +++++++------------ apps/portal/src/components/PopupModal.js | 10 ++++++++++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/apps/admin-x-settings/src/components/settings/membership/portal/PortalFrame.tsx b/apps/admin-x-settings/src/components/settings/membership/portal/PortalFrame.tsx index 9fee8d4efe..d4744d920d 100644 --- a/apps/admin-x-settings/src/components/settings/membership/portal/PortalFrame.tsx +++ b/apps/admin-x-settings/src/components/settings/membership/portal/PortalFrame.tsx @@ -15,17 +15,14 @@ const PortalFrame: React.FC = ({href, onDestroyed, selectedTab const [hasLoaded, setHasLoaded] = useState(false); const [isInvisible, setIsInvisible] = useState(true); - // Handler for making the iframe visible, memoized with useCallback const makeVisible = useCallback(() => { setTimeout(() => { if (iframeRef.current) { - setHasLoaded(true); setIsInvisible(false); } - }, 100); // Delay to allow scripts to render - }, [iframeRef]); // Dependencies for useCallback + }, 200); + }, [iframeRef]); - // Effect for attaching message listener useEffect(() => { const messageListener = (event: MessageEvent) => { if (!href) { @@ -34,15 +31,13 @@ const PortalFrame: React.FC = ({href, onDestroyed, selectedTab const originURL = new URL(event.origin); if (originURL.origin === new URL(href).origin) { - if (event.data === 'portal-ready' || event.data.type === 'portal-ready') { + if (event?.data?.type === 'portal-preview-ready') { makeVisible(); } } }; - if (hasLoaded) { - window.addEventListener('message', messageListener, true); - } + window.addEventListener('message', messageListener, true); return () => { window.removeEventListener('message', messageListener, true); @@ -55,17 +50,17 @@ const PortalFrame: React.FC = ({href, onDestroyed, selectedTab } return ( - <>{!hasLoaded &&
} + <>{!hasLoaded && isInvisible &&
}