Explorar o código

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

David Luzar %!s(int64=3) %!d(string=hai) anos
pai
achega
7dbd0c5e0a
Modificáronse 1 ficheiros con 10 adicións e 3 borrados
  1. 10 3
      src/components/LibraryUnit.tsx

+ 10 - 3
src/components/LibraryUnit.tsx

@@ -34,6 +34,11 @@ export const LibraryUnit = ({
 }) => {
   const ref = useRef<HTMLDivElement | null>(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);