diff --git a/packages/editor/src/extensions/web-clip/component.tsx b/packages/editor/src/extensions/web-clip/component.tsx index 5395a513c..ac8bfea7d 100644 --- a/packages/editor/src/extensions/web-clip/component.tsx +++ b/packages/editor/src/extensions/web-clip/component.tsx @@ -45,12 +45,14 @@ export function WebClipComponent( useEffect(() => { (async function () { - const iframe = embedRef.current; - if (!iframe || !iframe.contentDocument || !isLoading) return; + if (!isLoading) return; const html = await editor.storage .getAttachmentData?.(node.attrs) .catch(() => null); + + const iframe = embedRef.current; + if (!iframe || !iframe.contentDocument) return; iframe.contentDocument.open(); iframe.contentDocument.write( typeof html !== "string" || !html ? FAILED_CONTENT : html @@ -87,12 +89,15 @@ export function WebClipComponent( useEffect(() => { if (embedRef.current?.contentDocument) { resizeObserverRef.current = new ResizeObserver(() => { - resizeIframe(node.attrs, embedRef.current); + setTimeout(() => resizeIframe(node.attrs, embedRef.current), 100); }); resizeObserverRef.current.observe( embedRef.current?.contentDocument?.body ); } + return () => { + resizeObserverRef.current?.disconnect(); + }; }, []); return (