diff --git a/.changeset/sixty-rice-build.md b/.changeset/sixty-rice-build.md new file mode 100644 index 000000000..d1a0eca63 --- /dev/null +++ b/.changeset/sixty-rice-build.md @@ -0,0 +1,5 @@ +--- +'@craftjs/core': patch +--- + +Make parentId param optional in actions.add() diff --git a/packages/core/src/editor/actions.ts b/packages/core/src/editor/actions.ts index 3295d6de4..366d30b99 100644 --- a/packages/core/src/editor/actions.ts +++ b/packages/core/src/editor/actions.ts @@ -84,12 +84,7 @@ const Methods = ( iterateChildren(tree.rootNodeId, parentId); - if (!parentId) { - invariant( - tree.rootNodeId === ROOT_NODE, - 'Cannot add non-root Node without a parent' - ); - + if (!parentId && tree.rootNodeId === ROOT_NODE) { return; } @@ -180,7 +175,7 @@ const Methods = ( * @param parentId * @param index */ - add(nodeToAdd: Node | Node[], parentId: NodeId, index?: number) { + add(nodeToAdd: Node | Node[], parentId?: NodeId, index?: number) { // TODO: Deprecate adding array of Nodes to keep implementation simpler let nodes = [nodeToAdd]; if (Array.isArray(nodeToAdd)) {