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 &&
}