Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

Fix copy paste styles and props of descendants (#911)

Bogdan Chadkin22e54f8167b7
diff --git a/apps/designer/app/canvas/canvas.tsx b/apps/designer/app/canvas/canvas.tsx
index c827508e6d..32360857b8 100644
--- a/apps/designer/app/canvas/canvas.tsx
+++ b/apps/designer/app/canvas/canvas.tsx
@@ -1,6 +1,5 @@
import { useCallback, useMemo, useState } from "react";
import { computed } from "nanostores";
-import { useStore } from "@nanostores/react";
import store from "immerhin";
import type { CanvasData } from "@webstudio-is/project";
import {
@@ -27,10 +26,7 @@ import { WrapperComponentDev } from "./features/wrapper-component";
import {
propsIndexStore,
rootInstanceContainer,
- selectedInstanceStore,
useBreakpoints,
- useInstanceProps,
- useInstanceStyles,
useRootInstance,
useSetBreakpoints,
useSetProps,
@@ -43,7 +39,7 @@ import { useDragAndDrop } from "./shared/use-drag-drop";
import { utils } from "@webstudio-is/project";
import { useSubscribeDesignerReady } from "./shared/use-designer-ready";
import type { Asset } from "@webstudio-is/asset-uploader";
-import { useInstanceCopyPaste } from "~/shared/copy-paste";
+import { useCopyPasteInstance } from "~/shared/copy-paste";
import { customComponents } from "./custom-components";
import { useHoveredInstanceConnector } from "./hovered-instance-connector";
@@ -98,38 +94,6 @@ const useAssets = (initialAssets: Array<Asset>) => {
return assets;
};
-const useCopyPaste = () => {
- const selectedInstance = useStore(selectedInstanceStore);
- const instanceProps = useInstanceProps(selectedInstance?.id);
- const instanceStyles = useInstanceStyles(selectedInstance?.id);
-
- const selectedInstanceData = useMemo(() => {
- if (selectedInstance) {
- return {
- instance: selectedInstance,
- props: instanceProps,
- styles: instanceStyles,
- };
- }
- }, [selectedInstance, instanceProps, instanceStyles]);
-
- // We need to initialize this in both canvas and designer,
- // because the events will fire in either one, depending on where the focus is
- useInstanceCopyPaste({
- selectedInstanceData,
- allowAnyTarget: true,
- onCut: (instance) => {
- publish({ type: "deleteInstance", payload: { id: instance.id } });
- },
- onPaste: ({ instance, props, styles }) => {
- publish({
- type: "insertInstance",
- payload: { instance, props, styles },
- });
- },
- });
-};
-
const DesignMode = () => {
useManageDesignModeStyles();
useInsertInstance();
@@ -140,8 +104,9 @@ const DesignMode = () => {
useSubscribeScrollState();
usePublishTextEditingInstanceId();
useDragAndDrop();
- useCopyPaste();
-
+ // We need to initialize this in both canvas and designer,
+ // because the events will fire in either one, depending on where the focus is
+ useCopyPasteInstance();
useHoveredInstanceConnector();
return null;
diff --git a/apps/designer/app/canvas/shared/instance.ts b/apps/designer/app/canvas/shared/instance.ts
index e863ebcec9..8d820a8d48 100644
--- a/apps/designer/app/canvas/shared/instance.ts
+++ b/apps/designer/app/canvas/shared/instance.ts
@@ -1,18 +1,16 @@
import { useEffect } from "react";
import store from "immerhin";
-import type { Instance, Props, Styles } from "@webstudio-is/project-build";
+import type { Instance } from "@webstudio-is/project-build";
import { getComponentMeta } from "@webstudio-is/react-sdk";
import { utils, type InstanceInsertionSpec } from "@webstudio-is/project";
import { useSubscribe } from "~/shared/pubsub";
import {
- propsStore,
rootInstanceContainer,
- stylesStore,
selectedInstanceIdStore,
useTextEditingInstanceId,
} from "~/shared/nano-states";
import { publish } from "~/shared/pubsub";
-import { deleteInstanceMutable } from "~/shared/tree-utils";
+import { deleteInstance } from "~/shared/instance-utils";
declare module "~/shared/pubsub" {
export interface PubsubMap {
@@ -20,8 +18,6 @@ declare module "~/shared/pubsub" {
insertInstance: {
instance: Instance;
dropTarget?: { parentId: Instance["id"]; position: number };
- props?: Props;
- styles?: Styles;
};
}
}
@@ -57,39 +53,22 @@ export const findInsertLocation = (
};
export const useInsertInstance = () => {
- useSubscribe(
- "insertInstance",
- ({
- instance,
- dropTarget,
- props: insertedProps,
- styles: insertedStyles,
- }) => {
- const selectedInstanceId = selectedInstanceIdStore.get();
- store.createTransaction(
- [rootInstanceContainer, propsStore, stylesStore],
- (rootInstance, props, styles) => {
- if (rootInstance === undefined) {
- return;
- }
- const hasInserted = utils.tree.insertInstanceMutable(
- rootInstance,
- instance,
- dropTarget ?? findInsertLocation(rootInstance, selectedInstanceId)
- );
- if (hasInserted) {
- selectedInstanceIdStore.set(instance.id);
- }
- if (insertedProps !== undefined) {
- props.push(...insertedProps);
- }
- if (insertedStyles !== undefined) {
- styles.push(...insertedStyles);
- }
- }
+ useSubscribe("insertInstance", ({ instance, dropTarget }) => {
+ const selectedInstanceId = selectedInstanceIdStore.get();
+ store.createTransaction([rootInstanceContainer], (rootInstance) => {
+ if (rootInstance === undefined) {
+ return;
+ }
+ const hasInserted = utils.tree.insertInstanceMutable(
+ rootInstance,
+ instance,
+ dropTarget ?? findInsertLocation(rootInstance, selectedInstanceId)
);
- }
- );
+ if (hasInserted) {
+ selectedInstanceIdStore.set(instance.id);
+ }
+ });
+ });
};
export const useReparentInstance = () => {
@@ -117,28 +96,7 @@ export const useReparentInstance = () => {
export const useDeleteInstance = () => {
useSubscribe("deleteInstance", ({ id: deletedInstanceId }) => {
- const rootInstance = rootInstanceContainer.get();
- // @todo tell user they can't delete root
- if (deletedInstanceId === rootInstance?.id) {
- return;
- }
- store.createTransaction(
- [rootInstanceContainer, propsStore, stylesStore],
- (rootInstance, props, styles) => {
- if (rootInstance === undefined) {
- return;
- }
- const parentInstance = deleteInstanceMutable({
- rootInstance,
- props,
- styles,
- deletedInstanceId,
- });
- if (parentInstance) {
- selectedInstanceIdStore.set(parentInstance.id);
- }
- }
- );
+ deleteInstance(deletedInstanceId);
});
};
diff --git a/apps/designer/app/designer/designer.tsx b/apps/designer/app/designer/designer.tsx
index 03e29f881b..c536ff0a41 100644
--- a/apps/designer/app/designer/designer.tsx
+++ b/apps/designer/app/designer/designer.tsx
@@ -1,5 +1,4 @@
import { useCallback, useEffect, useMemo } from "react";
-import { useStore } from "@nanostores/react";
import { type Publish, usePublish, useSubscribe } from "~/shared/pubsub";
import {
type Pages,
@@ -28,17 +27,11 @@ import {
Workspace,
} from "./features/workspace";
import { usePublishShortcuts } from "./shared/shortcuts";
-import {
- selectedInstanceStore,
- useDragAndDropState,
- useInstanceProps,
- useInstanceStyles,
- useIsPreviewMode,
-} from "~/shared/nano-states";
+import { useDragAndDropState, useIsPreviewMode } from "~/shared/nano-states";
import { useClientSettings } from "./shared/client-settings";
import { Navigator } from "./features/sidebar-left";
import { designerUrl, getBuildUrl } from "~/shared/router-utils";
-import { useInstanceCopyPaste } from "~/shared/copy-paste";
+import { useCopyPasteInstance } from "~/shared/copy-paste";
import { AssetsProvider, usePublishAssets } from "./shared/assets";
registerContainers();
@@ -83,37 +76,6 @@ const useSubscribeCanvasReady = (publish: Publish) => {
});
};
-const useCopyPaste = (publish: Publish) => {
- const selectedInstance = useStore(selectedInstanceStore);
- const instanceProps = useInstanceProps(selectedInstance?.id);
- const instanceStyles = useInstanceStyles(selectedInstance?.id);
-
- const selectedInstanceData = useMemo(() => {
- if (selectedInstance) {
- return {
- instance: selectedInstance,
- props: instanceProps,
- styles: instanceStyles,
- };
- }
- }, [selectedInstance, instanceProps, instanceStyles]);
-
- // We need to initialize this in both canvas and designer,
- // because the events will fire in either one, depending on where the focus is
- useInstanceCopyPaste({
- selectedInstanceData,
- onCut: (instance) => {
- publish({ type: "deleteInstance", payload: { id: instance.id } });
- },
- onPaste: ({ instance, props, styles }) => {
- publish({
- type: "insertInstance",
- payload: { instance, props, styles },
- });
- },
- });
-};
-
const useSetWindowTitle = () => {
const [project] = useProject();
useEffect(() => {
@@ -302,7 +264,9 @@ export const Designer = ({
const { onRef: onRefReadCanvas, onTransitionEnd } = useReadCanvasRect();
const [dragAndDropState] = useDragAndDropState();
useSubscribeCanvasReady(publish);
- useCopyPaste(publish);
+ // We need to initialize this in both canvas and designer,
+ // because the events will fire in either one, depending on where the focus is
+ useCopyPasteInstance();
useSetWindowTitle();
const iframeRefCallback = useCallback(
(ref) => {
diff --git a/apps/designer/app/shared/copy-paste/copy-paste-instance.ts b/apps/designer/app/shared/copy-paste/copy-paste-instance.ts
index 92f2ec8b6b..c1ebba01d5 100644
--- a/apps/designer/app/shared/copy-paste/copy-paste-instance.ts
+++ b/apps/designer/app/shared/copy-paste/copy-paste-instance.ts
@@ -1,8 +1,18 @@
import ObjectId from "bson-objectid";
-import { useEffect } from "react";
+import store from "immerhin";
import { z } from "zod";
+import { useEffect } from "react";
import { Instance, Props, Styles } from "@webstudio-is/project-build";
import { utils } from "@webstudio-is/project";
+import { findInsertLocation } from "~/canvas/shared/instance";
+import {
+ rootInstanceContainer,
+ propsStore,
+ stylesStore,
+ selectedInstanceIdStore,
+} from "../nano-states";
+import { cloneInstance, findSubtree } from "../tree-utils";
+import { deleteInstance } from "../instance-utils";
import { startCopyPaste } from "./copy-paste";
const InstanceCopyData = z.object({
@@ -11,53 +21,116 @@ const InstanceCopyData = z.object({
styles: Styles,
});
-export type InstanceCopyData = z.infer<typeof InstanceCopyData>;
+type InstanceCopyData = z.infer<typeof InstanceCopyData>;
+
+const copyInstanceData = (targetInstanceId: string) => {
+ const rootInstance = rootInstanceContainer.get();
+ const props = propsStore.get();
+ const styles = stylesStore.get();
+ if (rootInstance === undefined) {
+ return;
+ }
+ // @todo tell user they can't copy or cut root
+ if (targetInstanceId === rootInstance.id) {
+ return;
+ }
+
+ const { targetInstance } = findSubtree(rootInstance, targetInstanceId);
+ if (targetInstance === undefined) {
+ return;
+ }
+ const { clonedInstance, clonedIds } = cloneInstance(targetInstance);
+
+ // clone props with new ids and link to new cloned instances
+ const clonedProps: Props = [];
+ for (const prop of props) {
+ const instanceId = clonedIds.get(prop.instanceId);
+ if (instanceId === undefined) {
+ continue;
+ }
+ clonedProps.push({
+ ...prop,
+ id: ObjectId().toString(),
+ instanceId,
+ });
+ }
+
+ // clone styles and link to new cloned instances
+ const clonedStyles: Styles = [];
+ for (const styleDecl of styles) {
+ const instanceId = clonedIds.get(styleDecl.instanceId);
+ if (instanceId === undefined) {
+ continue;
+ }
+ clonedStyles.push({
+ ...styleDecl,
+ instanceId,
+ });
+ }
+
+ return {
+ instance: clonedInstance,
+ props: clonedProps,
+ styles: clonedStyles,
+ };
+};
+
+const pasteInstance = (data: InstanceCopyData) => {
+ const selectedInstanceId = selectedInstanceIdStore.get();
+ store.createTransaction(
+ [rootInstanceContainer, propsStore, stylesStore],
+ (rootInstance, props, styles) => {
+ if (rootInstance === undefined) {
+ return;
+ }
+ const hasInserted = utils.tree.insertInstanceMutable(
+ rootInstance,
+ data.instance,
+ findInsertLocation(rootInstance, selectedInstanceId)
+ );
+ if (hasInserted === false) {
+ return;
+ }
+ props.push(...data.props);
+ styles.push(...data.styles);
+ selectedInstanceIdStore.set(data.instance.id);
+ }
+ );
+};
+
+const startCopyPasteInstance = () => {
+ return startCopyPaste({
+ version: "@webstudio/instance/v0.1",
+ type: InstanceCopyData,
+ allowAnyTarget: true,
+
+ onCopy: () => {
+ const selectedInstanceId = selectedInstanceIdStore.get();
+ if (selectedInstanceId === undefined) {
+ return;
+ }
+ return copyInstanceData(selectedInstanceId);
+ },
-type InstanceCopyPasteProps = {
- selectedInstanceData?: InstanceCopyData;
- allowAnyTarget?: boolean;
- onPaste: (data: InstanceCopyData) => void;
- onCut: (instance: Instance) => void;
+ onCut: () => {
+ const selectedInstanceId = selectedInstanceIdStore.get();
+ if (selectedInstanceId === undefined) {
+ return;
+ }
+ const data = copyInstanceData(selectedInstanceId);
+ if (data === undefined) {
+ return;
+ }
+ deleteInstance(selectedInstanceId);
+ return data;
+ },
+
+ onPaste: pasteInstance,
+ });
};
-// to make it easier to remove React from canvas if we need to
-export const useInstanceCopyPaste = (props: InstanceCopyPasteProps): void => {
- const { selectedInstanceData, allowAnyTarget, onPaste, onCut } = props;
+export const useCopyPasteInstance = (): void => {
useEffect(() => {
- return startCopyPaste({
- version: "@webstudio/instance/v0.1",
- type: InstanceCopyData,
- onCopy: () => {
- return selectedInstanceData;
- },
- onCut: () => {
- if (selectedInstanceData === undefined) {
- return;
- }
- onCut(selectedInstanceData.instance);
- return selectedInstanceData;
- },
- onPaste: (data: InstanceCopyData) => {
- const instance = utils.tree.cloneInstance(data.instance);
-
- // copy props with new ids and link to new instance
- const props: Props = data.props.map((prop) => {
- return {
- ...prop,
- id: ObjectId().toString(),
- instanceId: instance.id,
- };
- });
-
- const styles: Styles = data.styles.map((styleDecl) => {
- return {
- ...styleDecl,
- instanceId: instance.id,
- };
- });
-
- onPaste({ instance, props, styles });
- },
- });
- }, [selectedInstanceData, allowAnyTarget, onPaste, onCut]);
+ return startCopyPasteInstance();
+ }, []);
};
diff --git a/apps/designer/app/shared/instance-utils.ts b/apps/designer/app/shared/instance-utils.ts
new file mode 100644
index 0000000000..89a866f7c3
--- /dev/null
+++ b/apps/designer/app/shared/instance-utils.ts
@@ -0,0 +1,44 @@
+import store from "immerhin";
+import { Instance } from "@webstudio-is/project-build";
+import {
+ rootInstanceContainer,
+ propsStore,
+ stylesStore,
+ selectedInstanceIdStore,
+} from "./nano-states";
+import { findSubtree } from "./tree-utils";
+import { removeByMutable } from "./array-utils";
+
+export const deleteInstance = (targetInstanceId: Instance["id"]) => {
+ store.createTransaction(
+ [rootInstanceContainer, propsStore, stylesStore],
+ (rootInstance, props, styles) => {
+ if (rootInstance === undefined) {
+ return;
+ }
+ // @todo tell user they can't delete root
+ if (targetInstanceId === rootInstance?.id) {
+ return;
+ }
+ const { parentInstance, subtreeIds } = findSubtree(
+ rootInstance,
+ targetInstanceId
+ );
+ if (parentInstance === undefined) {
+ return;
+ }
+
+ removeByMutable(
+ parentInstance.children,
+ (child) => child.type === "instance" && child.id === targetInstanceId
+ );
+ // delete props and styles of deleted instance and its descendants
+ removeByMutable(props, (prop) => subtreeIds.has(prop.instanceId));
+ removeByMutable(styles, (styleDecl) =>
+ subtreeIds.has(styleDecl.instanceId)
+ );
+
+ selectedInstanceIdStore.set(parentInstance.id);
+ }
+ );
+};
diff --git a/apps/designer/app/shared/tree-utils.test.ts b/apps/designer/app/shared/tree-utils.test.ts
index b3a0b8b7f8..a55a44cc98 100644
--- a/apps/designer/app/shared/tree-utils.test.ts
+++ b/apps/designer/app/shared/tree-utils.test.ts
@@ -1,6 +1,6 @@
import { test, expect } from "@jest/globals";
-import type { Instance, Props, Styles } from "@webstudio-is/project-build";
-import { deleteInstanceMutable } from "./tree-utils";
+import type { Instance } from "@webstudio-is/project-build";
+import { cloneInstance, findSubtree } from "./tree-utils";
const createInstance = (id: string, children: Instance[]): Instance => {
return {
@@ -11,29 +11,7 @@ const createInstance = (id: string, children: Instance[]): Instance => {
};
};
-const createProp = (id: string, instanceId: string): Props[number] => {
- return {
- type: "string",
- id,
- instanceId,
- name: "prop",
- value: "value",
- };
-};
-
-const createStyleDecl = (instanceId: string): Styles[number] => {
- return {
- breakpointId: "breakpoint",
- instanceId,
- property: "width",
- value: {
- type: "keyword",
- value: "keyword",
- },
- };
-};
-
-test("delete instance with own and descendants styles and props", () => {
+test("find subtree with all descendants and parent instance", () => {
const rootInstance: Instance = createInstance("root", [
createInstance("box1", []),
createInstance("box2", [
@@ -45,53 +23,49 @@ test("delete instance with own and descendants styles and props", () => {
]),
createInstance("box4", []),
]);
- const props: Props = [
- createProp("1", "root"),
- createProp("2", "box1"),
- createProp("3", "box2"),
- createProp("4", "box3"),
- createProp("7", "child3"),
- createProp("6", "child2"),
- createProp("5", "child1"),
- createProp("8", "descendant"),
- createProp("9", "box4"),
- ];
- const styles: Styles = [
- createStyleDecl("root"),
- createStyleDecl("box1"),
- createStyleDecl("box2"),
- createStyleDecl("box3"),
- createStyleDecl("child3"),
- createStyleDecl("child2"),
- createStyleDecl("child1"),
- createStyleDecl("descendant"),
- createStyleDecl("box4"),
- ];
- deleteInstanceMutable({
- rootInstance,
- props,
- styles,
- deletedInstanceId: "box3",
+ expect(findSubtree(rootInstance, "box3")).toEqual({
+ parentInstance: createInstance("box2", [
+ createInstance("box3", [
+ createInstance("child1", []),
+ createInstance("child2", [createInstance("descendant", [])]),
+ createInstance("child3", []),
+ ]),
+ ]),
+ targetInstance: createInstance("box3", [
+ createInstance("child1", []),
+ createInstance("child2", [createInstance("descendant", [])]),
+ createInstance("child3", []),
+ ]),
+ subtreeIds: new Set(["box3", "child1", "child2", "child3", "descendant"]),
+ });
+
+ expect(findSubtree(rootInstance, "not_found")).toEqual({
+ parentInstance: undefined,
+ targetInstance: undefined,
+ subtreeIds: new Set(),
});
- expect(rootInstance).toEqual(
- createInstance("root", [
- createInstance("box1", []),
- createInstance("box2", []),
- createInstance("box4", []),
+ expect(findSubtree(rootInstance, "root").parentInstance).toEqual(undefined);
+});
+
+test("clone instance tree and provide cloned ids map", () => {
+ const instance = createInstance("box", [
+ createInstance("child1", []),
+ createInstance("child2", [createInstance("descendant", [])]),
+ createInstance("child3", []),
+ ]);
+ const { clonedInstance, clonedIds } = cloneInstance(instance);
+ const string = expect.any(String) as unknown as string;
+ expect(clonedInstance).toEqual(
+ createInstance(string, [
+ createInstance(string, []),
+ createInstance(string, [createInstance(string, [])]),
+ createInstance(string, []),
])
);
- expect(props).toEqual([
- createProp("1", "root"),
- createProp("2", "box1"),
- createProp("3", "box2"),
- createProp("9", "box4"),
- ]);
- expect(styles).toEqual([
- createStyleDecl("root"),
- createStyleDecl("box1"),
- createStyleDecl("box2"),
- createStyleDecl("box4"),
- ]);
+ expect(clonedIds.get(instance.id)).toEqual(clonedInstance.id);
+ expect(clonedIds.get((instance.children[0] as Instance).id)).toEqual(
+ (clonedInstance.children[0] as Instance).id
+ );
});
diff --git a/apps/designer/app/shared/tree-utils.ts b/apps/designer/app/shared/tree-utils.ts
index 4d081f8040..b39f5708fe 100644
--- a/apps/designer/app/shared/tree-utils.ts
+++ b/apps/designer/app/shared/tree-utils.ts
@@ -1,5 +1,6 @@
-import type { Instance, Props, Styles } from "@webstudio-is/project-build";
-import { removeByMutable } from "./array-utils";
+import ObjectId from "bson-objectid";
+import produce from "immer";
+import type { Instance } from "@webstudio-is/project-build";
const traverseInstances = (
instance: Instance,
@@ -16,46 +17,48 @@ const traverseInstances = (
}
};
-export const deleteInstanceMutable = ({
- rootInstance,
- props,
- styles,
- deletedInstanceId,
-}: {
- rootInstance: Instance;
- props: Props;
- styles: Styles;
- deletedInstanceId: string;
-}) => {
- const parentInstances = new Map<Instance["id"], Instance>();
- const deletedInstances = new Set<Instance["id"]>();
+export const findSubtree = (
+ rootInstance: Instance,
+ targetInstanceId: Instance["id"]
+) => {
+ const instancesById = new Map<Instance["id"], Instance>();
+ const parentInstancesById = new Map<Instance["id"], Instance>();
+ const subtreeIds = new Set<Instance["id"]>();
traverseInstances(rootInstance, (child, instance) => {
- parentInstances.set(child.id, instance);
- // mark as deleted the instance
- if (child.id === deletedInstanceId) {
- deletedInstances.add(child.id);
+ // add target instance
+ if (child.id === targetInstanceId) {
+ subtreeIds.add(child.id);
+ parentInstancesById.set(child.id, instance);
+ instancesById.set(child.id, child);
}
- // and all descendants of deleted instance
- if (deletedInstances.has(instance.id)) {
- deletedInstances.add(child.id);
+ // add all descendants of target instance
+ if (subtreeIds.has(instance.id)) {
+ subtreeIds.add(child.id);
}
});
- const parentInstance = parentInstances.get(deletedInstanceId);
- if (parentInstance === undefined) {
- return;
- }
-
- removeByMutable(
- parentInstance.children,
- (child) => child.type === "instance" && child.id === deletedInstanceId
- );
- // delete props and styles of deleted instance and its descendants
- removeByMutable(props, (prop) => deletedInstances.has(prop.instanceId));
- removeByMutable(styles, (styleDecl) =>
- deletedInstances.has(styleDecl.instanceId)
- );
+ return {
+ parentInstance: parentInstancesById.get(targetInstanceId),
+ targetInstance: instancesById.get(targetInstanceId),
+ subtreeIds,
+ };
+};
- return parentInstance;
+export const cloneInstance = (targetInstance: Instance) => {
+ const clonedIds = new Map<Instance["id"], Instance["id"]>();
+ const clonedInstance = produce((targetInstance) => {
+ const newId = ObjectId().toString();
+ clonedIds.set(targetInstance.id, newId);
+ targetInstance.id = newId;
+ traverseInstances(targetInstance, (instance) => {
+ const newId = ObjectId().toString();
+ clonedIds.set(instance.id, newId);
+ instance.id = newId;
+ });
+ })(targetInstance);
+ return {
+ clonedIds,
+ clonedInstance,
+ };
};
diff --git a/packages/project/src/shared/tree-utils/clone-instance.test.ts b/packages/project/src/shared/tree-utils/clone-instance.test.ts
deleted file mode 100644
index 87a3743b43..0000000000
--- a/packages/project/src/shared/tree-utils/clone-instance.test.ts
+++ /dev/null
@@ -1,45 +0,0 @@
-import { describe, test, expect } from "@jest/globals";
-import type { Instance } from "@webstudio-is/project-build";
-import { cloneInstance } from "./clone-instance";
-
-const getIds = (instance: Instance, ids: Array<Instance["id"]> = []) => {
- ids.push(instance.id);
- for (const child of instance.children) {
- if (child.type === "instance") {
- getIds(child);
- }
- }
- return ids;
-};
-
-describe("Clone instance", () => {
- test("ensure new ids", () => {
- const instance: Instance = {
- type: "instance",
- component: "Box",
- id: "1",
- children: [
- {
- type: "instance",
- component: "Box",
- id: "2",
- children: [
- {
- type: "instance",
- component: "Box",
- id: "3",
- children: [],
- },
- ],
- },
- ],
- };
-
- const ids = getIds(instance);
- const clone = cloneInstance(instance);
- const clonedIds = getIds(clone);
- ids.forEach((id, index) => {
- expect(id).not.toBe(clonedIds[index]);
- });
- });
-});
diff --git a/packages/project/src/shared/tree-utils/clone-instance.ts b/packages/project/src/shared/tree-utils/clone-instance.ts
deleted file mode 100644
index 7293014db6..0000000000
--- a/packages/project/src/shared/tree-utils/clone-instance.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import ObjectId from "bson-objectid";
-import produce from "immer";
-import type { Instance } from "@webstudio-is/project-build";
-
-const updateIds = (instance: Instance) => {
- instance.id = ObjectId().toString();
- for (const child of instance.children) {
- if (child.type === "text") {
- continue;
- }
- updateIds(child);
- }
-};
-
-export const cloneInstance = (instance: Instance): Instance =>
- produce(updateIds)(instance);
diff --git a/packages/project/src/shared/tree-utils/index.ts b/packages/project/src/shared/tree-utils/index.ts
index 8c4a2f71e3..f78e49adda 100644
--- a/packages/project/src/shared/tree-utils/index.ts
+++ b/packages/project/src/shared/tree-utils/index.ts
@@ -5,7 +5,6 @@ export * from "./find-instance";
export * from "./get-instance-path";
export * from "./find-closest-sibling-instance";
export * from "./find-parent-instance";
-export * from "./clone-instance";
export * from "./reparent-instance";
export * from "./find-closest-non-inline-parent";
export * from "./set-instance-children";