Fix: Assertion failure with inserting child with id into orphaned subtree

Fix #1874