Skip to content

Commit

Permalink
fix: make parentId param optional in actions.add() (#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
prevwong committed May 13, 2024
1 parent fcc71d8 commit b25469e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-rice-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@craftjs/core': patch
---

Make parentId param optional in actions.add()
9 changes: 2 additions & 7 deletions packages/core/src/editor/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit b25469e

Please sign in to comment.