Hello,
Detaching a Behavior from within another Behavior’s detach method can lead to unexpected behavior (pun not intended).
Node.removeBehavior is currently implemented like this:
public removeBehavior(behavior: Behavior<Node>): Node {
const index = this._behaviors.indexOf(behavior);
if (index === -1) {
return this;
}
this._behaviors[index].detach();
this._behaviors.splice(index, 1);
return this;
}
The issue is that the index is computed before calling detach().
If a custom Behavior removes another Behavior during its own detach execution, the _behaviors array can change, making the previously computed index invalid before splice() is executed.`
The issue is also present on the current master branch on GitHub, so I assume it has not been identified yet.