From 8dada6d93600461a784a025dd37be123a34ff945 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Thu, 7 Mar 2024 13:25:21 +0500 Subject: [PATCH] editor: fix crash on loading web clip --- packages/editor/src/extensions/web-clip/component.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 (