From a10a64c6330bfc43f029417f8314625cf6cc9560 Mon Sep 17 00:00:00 2001 From: Princi Vershwal Date: Wed, 24 Jan 2024 20:20:32 +0530 Subject: [PATCH] Optimised for iframe (#19573) --- .../components/settings/membership/portal/PortalFrame.tsx | 8 +------- 1 file changed, 1 insertion(+), 7 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 c0ffd5aeb2..96f2b53bf6 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 @@ -14,7 +14,6 @@ const PortalFrame: React.FC = ({href, onDestroyed, selectedTab const iframeRef = useRef(null); const [hasLoaded, setHasLoaded] = useState(false); const [isInvisible, setIsInvisible] = useState(true); - const makeVisible = useCallback(() => { setTimeout(() => { if (iframeRef.current) { @@ -22,29 +21,24 @@ const PortalFrame: React.FC = ({href, onDestroyed, selectedTab } }, 300); }, [iframeRef]); - useEffect(() => { const messageListener = (event: MessageEvent) => { if (!href) { return; } const originURL = new URL(event.origin); - if (originURL.origin === new URL(href).origin) { if (event?.data?.type === 'portal-preview-ready') { makeVisible(); } } }; - window.addEventListener('message', messageListener, true); - return () => { window.removeEventListener('message', messageListener, true); onDestroyed?.(); }; }, [href, onDestroyed, makeVisible, hasLoaded]); - if (!href) { return null; } @@ -67,4 +61,4 @@ const PortalFrame: React.FC = ({href, onDestroyed, selectedTab ); }; -export default PortalFrame; +export default PortalFrame; \ No newline at end of file