Skip to content

Commit ba3c964

Browse files
authored
fix: cleanup parent children when delete instances (#4859)
Was missed while refactoring. Wrong data was mutated.
1 parent 4855ffd commit ba3c964

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

apps/builder/app/shared/instance-utils.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,8 @@ describe("delete instance", () => {
740740
expect(data.instances.get("bodyId")?.children.length).toEqual(2);
741741
deleteInstanceMutable(
742742
data,
743-
getInstancePath(["boxId", "bodyId"], data.instances)
743+
// clone to make sure data is mutated instead of instance path
744+
structuredClone(getInstancePath(["boxId", "bodyId"], data.instances))
744745
);
745746
expect(data.instances.size).toEqual(2);
746747
expect(data.instances.get("bodyId")?.children.length).toEqual(1);

apps/builder/app/shared/instance-utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ export const deleteInstanceMutable = (
443443
instanceIds
444444
);
445445

446+
// mutate instances from data instead of instance path
447+
parentInstance = data.instances.get(parentInstance?.id as string);
446448
// may not exist when delete root
447449
if (parentInstance) {
448450
removeByMutable(

0 commit comments

Comments
 (0)