From ab6b3b6ba2eda415d7e1ae0c2dfdbd17470219e5 Mon Sep 17 00:00:00 2001 From: thecodrr Date: Fri, 20 Nov 2020 22:43:02 +0500 Subject: [PATCH] fix: crash in editor due to ResizeObserver loop limit exceeded --- apps/web/src/components/editor/titlebox.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/editor/titlebox.js b/apps/web/src/components/editor/titlebox.js index 7a22127f2..88c932633 100644 --- a/apps/web/src/components/editor/titlebox.js +++ b/apps/web/src/components/editor/titlebox.js @@ -18,12 +18,18 @@ function TitleBox(props) { }, []); useEffect(() => { + console.log("hello"); if (!window.ResizeObserver) return; const myObserver = new ResizeObserver((entries) => { - const newHeight = entries[0].contentRect.height; - setHeight(newHeight > 60 ? newHeight : 60); + window.requestAnimationFrame(() => { + const newHeight = entries[0].contentRect.height; + setHeight(newHeight > 60 ? newHeight : 60); + }); }); myObserver.observe(document.querySelector(".dummyEditorTitle")); + return () => { + myObserver.disconnect(); + }; }, []); useEffect(() => {