diff --git a/components/media-or-link.js b/components/media-or-link.js index 11c2f4f6..6a42e907 100644 --- a/components/media-or-link.js +++ b/components/media-or-link.js @@ -205,28 +205,21 @@ function TweetSkeleton ({ className }) { ) } -export const useFrameHeight = ( - iframeRef -) => { - const [height, setHeight] = useState(0) - const iframeCurrent = iframeRef.current +export const NostrEmbed = memo(function NostrEmbed ({ src, className, topLevel, id }) { + const [show, setShow] = useState(false) + const iframeRef = useRef(null) + useEffect(() => { const setHeightFromIframe = (e) => { - if (e.origin !== 'https://njump.me' || !e?.data?.height) return - setHeight(e.data.height) + if (e.origin !== 'https://njump.me' || !e?.data?.height || e.source !== iframeRef.current.contentWindow) return + iframeRef.current.height = `${e.data.height}px` } window?.addEventListener('message', setHeightFromIframe) return () => { window?.removeEventListener('message', setHeightFromIframe) } - }, [iframeCurrent]) - return height -} + }, [iframeRef.current]) -export const NostrEmbed = memo(function NostrEmbed ({ src, className, topLevel, id }) { - const [show, setShow] = useState(false) - const iframeRef = useRef(null) - const frameHeight = useFrameHeight(iframeRef) return (