From 8bcdca4526867433f99fdfcb55a063668db0c9dc Mon Sep 17 00:00:00 2001 From: David Luzar <5153846+dwelle@users.noreply.github.com> Date: Sat, 31 Oct 2026 17:48:47 +0100 Subject: [PATCH] fix(editor): ignore deleted elements when inserting frame children (#12510) fix(editor): place new frame children below the frame despite deleted children Deleted frame children keep their frameId and index, so one left above the frame made new children of that frame (created or dragged in) go above it, up to the top of the canvas, until a reload dropped the deleted elements. Only live children count now. Claude Opus 5.5 (xhigh) --- packages/element/src/frame.ts | 4 ++- packages/element/tests/frame.test.tsx | 44 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/packages/element/src/frame.ts b/packages/element/src/frame.ts index d74c99eb14..49c65aee24 100644 --- a/packages/element/src/frame.ts +++ b/packages/element/src/frame.ts @@ -553,7 +553,9 @@ export const getFrameChildrenInsertionIndex = ( if (element.id === frameId) { return index; - } else if (element.frameId === frameId) { + } else if (element.frameId === frameId && !element.isDeleted) { + // deleted children keep their frameId (and index), but don't count: + // they'd place the new ones as high as they were return index + 1; } } diff --git a/packages/element/tests/frame.test.tsx b/packages/element/tests/frame.test.tsx index d05b752fcf..4cbb310abc 100644 --- a/packages/element/tests/frame.test.tsx +++ b/packages/element/tests/frame.test.tsx @@ -439,6 +439,50 @@ describe("adding elements to frames", () => { ]); }); + it("should insert a newly created frame child below its frame despite deleted frame children above it", () => { + const frameChild = API.createElement({ + id: "frameChild", + type: "rectangle", + x: 100, + y: 20, + width: 20, + height: 20, + frameId: frame.id, + }); + const deletedFrameChild = API.createElement({ + id: "deletedFrameChild", + type: "rectangle", + x: 100, + y: 60, + width: 20, + height: 20, + frameId: frame.id, + isDeleted: true, + }); + + API.setElements([frameChild, frame, deletedFrameChild]); + + UI.clickTool("rectangle"); + mouse.downAt(20, 20); + mouse.moveTo(40, 40); + mouse.upAt(40, 40); + + const createdElement = h.elements.find( + (element) => + element.id !== frame.id && + element.id !== frameChild.id && + element.id !== deletedFrameChild.id, + ); + + expect(createdElement?.frameId).toBe(frame.id); + expect(h.elements.map((element) => element.id)).toEqual([ + frameChild.id, + createdElement?.id, + frame.id, + deletedFrameChild.id, + ]); + }); + it("should insert a newly created frame child above the highest frame child", () => { const frameChildUnderCursor = API.createElement({ id: "frameChildUnderCursor",