The issue is split from https://phabricator.wikimedia.org/T89923. The issue is present in beta, test2, and production - see the attached screencast.
Re-arranging the categories(dragging them), then deleting them, and hitting 'Cancel' - causes errors when the Options-Categories dialog is re-opened.
- Add three categories - AA, BB, CC
- Move CC category - insert it in front of BB, then in front of AA (the sequence seems to be important)
- Delete AA and BB - click 'Cancel'
- Re-open Categories - CC category remains displayed.
- Click CC to delete -
Error: Cannot remove detached item
and sometime
TypeError: this.categories[name] is undefined
The issue is not too serious- those 'detached' categories are not saved.