Correct way to delete a descendant

I want to delete descendant. using content.content.splice(index,1) but this is throwing error Cannot read property 'nodeSize' of undefined

Please help!

Nodes and their content are immutable. Don’t call methods like splice on them. You’ll want to create a transactions that deletes the range covered by the node you want to delete.

but I require this on slice. I don’t want to actually mutate the document. I am using this inside handlePaste method and applying on slice.

Then you create a new fragment by appending the part before the node to the part after it, and then use use the node’s copy method to create a new node with the new fragment.

could you share some reference please.

previously I was using nested forEach and the result was good enough.

Could you elaborate why nodes and their content should be immutable, even on the slice object ?

Types that are sometimes immutable are a pain to work with (unless you have a Rust-like system to declare and check writeable access), since it’s really easy to change a value that happens to be shared with some place that expects it to be immutable. So since the editor state is immutable, all the types that are part of it are immutable too.

forEach is probably also a good way to do this. Something like:

function removeChild(node, n) {
  let children = []
  node.forEach((child, _, i) => {
    if (i != n) children.push(child)
  return node.copy(Fragment.from(children))