Browse Source

fix: library ids cross-contamination on multiple insert (#6466)

David Luzar 2 years ago
parent
commit
e9064a4a87
1 changed files with 9 additions and 1 deletions
  1. 9 1
      src/components/LibraryMenuItems.tsx

+ 9 - 1
src/components/LibraryMenuItems.tsx

@@ -12,6 +12,7 @@ import { MIME_TYPES } from "../constants";
 import Spinner from "./Spinner";
 import LibraryMenuBrowseButton from "./LibraryMenuBrowseButton";
 import clsx from "clsx";
+import { duplicateElements } from "../element/newElement";
 
 const CELLS_PER_ROW = 4;
 
@@ -96,7 +97,14 @@ const LibraryMenuItems = ({
     } else {
       targetElements = libraryItems.filter((item) => item.id === id);
     }
-    return targetElements;
+    return targetElements.map((item) => {
+      return {
+        ...item,
+        // duplicate each library item before inserting on canvas to confine
+        // ids and bindings to each library item. See #6465
+        elements: duplicateElements(item.elements),
+      };
+    });
   };
 
   const createLibraryItemCompo = (params: {