Skip to content

Commit

Permalink
fix: cleanup parent children when delete instances
Browse files Browse the repository at this point in the history
Was missed while refactoring. Wrong data was mutated.
  • Loading branch information
TrySound committed Feb 12, 2025
1 parent 9e710f4 commit dce1f14
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion apps/builder/app/shared/instance-utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,8 @@ describe("delete instance", () => {
expect(data.instances.get("bodyId")?.children.length).toEqual(2);
deleteInstanceMutable(
data,
getInstancePath(["boxId", "bodyId"], data.instances)
// clone to make sure data is mutated instead of instance path
structuredClone(getInstancePath(["boxId", "bodyId"], data.instances))
);
expect(data.instances.size).toEqual(2);
expect(data.instances.get("bodyId")?.children.length).toEqual(1);
Expand Down
2 changes: 2 additions & 0 deletions apps/builder/app/shared/instance-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ export const deleteInstanceMutable = (
instanceIds
);

// mutate instances from data instead of instance path
parentInstance = data.instances.get(parentInstance?.id as string);
// may not exist when delete root
if (parentInstance) {
removeByMutable(
Expand Down

0 comments on commit dce1f14

Please sign in to comment.