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 insert into container without children (#1802)

Bogdan Chadkin64f3f372568b
diff --git a/apps/builder/app/shared/tree-utils.test.ts b/apps/builder/app/shared/tree-utils.test.ts
index 7b23c0bf0d..a31bfbe4c1 100644
--- a/apps/builder/app/shared/tree-utils.test.ts
+++ b/apps/builder/app/shared/tree-utils.test.ts
@@ -361,6 +361,28 @@ describe("insert instances into container with text or rich text children", () =
createInstancePair("inserted", "Box", []),
]);
});
+
+ test("insert container without children", () => {
+ const getInstances = () =>
+ new Map([createInstancePair("root", "Body", [])]);
+
+ const instances1 = getInstances();
+ insertInstancesMutable(
+ instances1,
+ new Map(),
+ baseMetasMap,
+ [createInstance("inserted", "Box", [])],
+ [{ type: "id", value: "inserted" }],
+ {
+ parentSelector: ["root"],
+ position: 1,
+ }
+ );
+ expect(Array.from(instances1.entries())).toEqual([
+ createInstancePair("root", "Body", [{ type: "id", value: "inserted" }]),
+ createInstancePair("inserted", "Box", []),
+ ]);
+ });
});
test("reparent instance into target", () => {
diff --git a/apps/builder/app/shared/tree-utils.ts b/apps/builder/app/shared/tree-utils.ts
index 35a48e2dba..d43cc06d1b 100644
--- a/apps/builder/app/shared/tree-utils.ts
+++ b/apps/builder/app/shared/tree-utils.ts
@@ -133,7 +133,7 @@ const wrapEditableChildrenAroundDropTargetMutable = (
) => {
const [parentId] = dropTarget.parentSelector;
const parentInstance = instances.get(parentId);
- if (parentInstance === undefined) {
+ if (parentInstance === undefined || parentInstance.children.length === 0) {
return;
}
// wrap only containers with text and rich text childre