You are calling replace from your change filter. Those should definitely not have side effects—they are called as part of creating a transaction. By dispatching another transaction as a transaction is being built up, you are moving the view forward before that first transaction is applied, causing this error.
I had to replace the changeFilter with a transactionFilter.
I was using the changeFilter because I wanted to replicate the beforeChange
event and this comment says this is the way to go.
Breaking paste like this sounds like a rather bad idea, and you might also be able to just handle the browser’s "paste" event, but other than that this looks like it would work.