From 7dbd0c5e0aee6f2296a7a43d84479920ba3894d0 Mon Sep 17 00:00:00 2001 From: David Luzar Date: Fri, 22 Oct 2021 22:07:20 +0200 Subject: [PATCH] fix: clear `LibraryUnit` DOM on unmount (#4084) --- src/components/LibraryUnit.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/LibraryUnit.tsx b/src/components/LibraryUnit.tsx index 3e4a8986fa..5b22762c61 100644 --- a/src/components/LibraryUnit.tsx +++ b/src/components/LibraryUnit.tsx @@ -34,6 +34,11 @@ export const LibraryUnit = ({ }) => { const ref = useRef(null); useEffect(() => { + const node = ref.current; + if (!node) { + return; + } + (async () => { const elementsToRender = elements || pendingElements; if (!elementsToRender) { @@ -47,10 +52,12 @@ export const LibraryUnit = ({ }, files, ); - if (ref.current) { - ref.current.innerHTML = svg.outerHTML; - } + node.innerHTML = svg.outerHTML; })(); + + return () => { + node.innerHTML = ""; + }; }, [elements, pendingElements, files]); const [isHovered, setIsHovered] = useState(false);