I don’t see what might be going wrong, but using global mutable arrays to communicate with state apply methods is a bad idea. If you can derive which decorations should be removed from the transaction (which you typically can), you should do that in the apply method, not when dispatching.
Possibly related, immediately re-adding decorations that are removed by mapping seems extremely suspicious. What is the intention there?
Thanks for help and coding tips. I will try it out.
I am using ProseMirror for an editor with “inline comments”. These comments, I not only want to wrap in a node, but also add uneditable text as widgets at start and end, to always have a serialized representation of the commented text available when I retrieve the textContent of the editor element. This is what I save in my database and also present to users through the widget decorations.
When text is removed at the position of the widgets they are also removed by ProseMirror, but I usually want to keep them because my comments are usually still there.