Trying to fix browser tests (#19575)
This commit is contained in:
parent
938d23ec33
commit
58ec6792d9
@ -6,6 +6,7 @@ type PortalFrameProps = {
|
||||
onDestroyed?: () => void;
|
||||
selectedTab?: string;
|
||||
}
|
||||
|
||||
const PortalFrame: React.FC<PortalFrameProps> = ({href, onDestroyed, selectedTab}) => {
|
||||
if (!selectedTab) {
|
||||
selectedTab = 'signup';
|
||||
@ -13,6 +14,7 @@ const PortalFrame: React.FC<PortalFrameProps> = ({href, onDestroyed, selectedTab
|
||||
const iframeRef = useRef<HTMLIFrameElement>(null);
|
||||
const [hasLoaded, setHasLoaded] = useState<boolean>(false);
|
||||
const [isInvisible, setIsInvisible] = useState<boolean>(true);
|
||||
|
||||
const makeVisible = useCallback(() => {
|
||||
setTimeout(() => {
|
||||
if (iframeRef.current) {
|
||||
@ -20,24 +22,29 @@ const PortalFrame: React.FC<PortalFrameProps> = ({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;
|
||||
}
|
||||
@ -60,4 +67,4 @@ const PortalFrame: React.FC<PortalFrameProps> = ({href, onDestroyed, selectedTab
|
||||
);
|
||||
};
|
||||
|
||||
export default PortalFrame;
|
||||
export default PortalFrame;
|
||||
|
Loading…
Reference in New Issue
Block a user