### Godot version

v4.1.rc1.official [1f9e540f1]

### System information

Windows 10

### Issue description

Attempting to reorder the children of a TabContainer results in an unintended ordering and incorrect undo states.

Also happens in v4.0.3.stable.official [5222a99f5].

https://github.com/godotengine/godot/assets/3820082/2c2458e3-88ad-46d9-8a04-f289a049984a



### Steps to reproduce

1. Add a new TabContainer
2. Add a few children to it
3. Drag and drop to erroneously reorder them
4. Attempt to undo the change

### Minimal reproduction project

N/A
}
	}
	String newname = n->get_name();
	List<Node *> to_erase;
	for (int i = 0; i < n->get_child_count(); i++) {
		if (n->get_child(i)->get_owner() == nullptr && n->is_owned_by_parent()) {
			to_erase.push_back(n->get_child(i));
		}
	}
	n->replace_by(newnode, true);
	
	for (int i = 0; i < newnode->get_child_count(); i++) {
		Node *c = newnode->get_child(i);
		c->call("set_transform", c->call("get_transform"));
	}
	
	if (p_remove_old) {
		EditorUndoRedoManager::get_singleton()->clear_history();
	}
	newnode->set_name(newname);
	_push_item(newnode);
	if (p_remove_old) {
		memdelete(n);
		while (to_erase.front()) {
			memdelete(to_erase.front()->get());
			to_erase.pop_front();
		}
	}
}
void SceneTreeDock::perform_node_replace(Node *p_base, Node *p_node, Node *p_by_node) {