diff --git a/packages/core/client/src/schema-component/hooks/useDesignable.tsx b/packages/core/client/src/schema-component/hooks/useDesignable.tsx index 94b3eef3e..b989cb8b5 100644 --- a/packages/core/client/src/schema-component/hooks/useDesignable.tsx +++ b/packages/core/client/src/schema-component/hooks/useDesignable.tsx @@ -460,22 +460,6 @@ export class Designable { } const opts = { onSuccess: options?.onSuccess }; const { wrap = defaultWrap, breakRemoveOn, removeParentsIfNoChildren } = options; - if (Schema.isSchemaInstance(schema)) { - if (this.parentsIn(schema)) { - this.emit('error', { - code: 'parent_is_not_allowed', - schema, - }); - return; - } - schema.parent.removeProperty(schema.name); - if (removeParentsIfNoChildren) { - opts['removed'] = this.recursiveRemoveIfNoChildren(schema.parent, { breakRemoveOn }); - } - schema.parent = null; - } else if (schema) { - schema = cloneDeep(schema); - } let order = 0; let newOrder = 0; @@ -496,6 +480,23 @@ export class Designable { } }); + if (Schema.isSchemaInstance(schema)) { + if (this.parentsIn(schema)) { + this.emit('error', { + code: 'parent_is_not_allowed', + schema, + }); + return; + } + schema.parent.removeProperty(schema.name); + if (removeParentsIfNoChildren) { + opts['removed'] = this.recursiveRemoveIfNoChildren(schema.parent, { breakRemoveOn }); + } + schema.parent = null; + } else if (schema) { + schema = cloneDeep(schema); + } + this.prepareProperty(schema); const wrapped = wrap(schema); const s = this.current.parent.addProperty(wrapped.name || uid(), wrapped);