fix: clear `LibraryUnit` DOM on unmount (#4084)

pull/4089/head
David Luzar 3 years ago committed by GitHub
parent ba35eb8f8c
commit 7dbd0c5e0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -34,6 +34,11 @@ export const LibraryUnit = ({
}) => { }) => {
const ref = useRef<HTMLDivElement | null>(null); const ref = useRef<HTMLDivElement | null>(null);
useEffect(() => { useEffect(() => {
const node = ref.current;
if (!node) {
return;
}
(async () => { (async () => {
const elementsToRender = elements || pendingElements; const elementsToRender = elements || pendingElements;
if (!elementsToRender) { if (!elementsToRender) {
@ -47,10 +52,12 @@ export const LibraryUnit = ({
}, },
files, files,
); );
if (ref.current) { node.innerHTML = svg.outerHTML;
ref.current.innerHTML = svg.outerHTML;
}
})(); })();
return () => {
node.innerHTML = "";
};
}, [elements, pendingElements, files]); }, [elements, pendingElements, files]);
const [isHovered, setIsHovered] = useState(false); const [isHovered, setIsHovered] = useState(false);

Loading…
Cancel
Save