Pressing backspace introducing odd ReplaceStep

Hi! The project I’m currently working on has a pretty messy plugin for tracking changes and approving/rejecting insertions/deletions. The problem we’re now having is that, presumably after a ProseMirror update, when pressing backspace before a space character, ProseMirror is creating a ReplaceStep that replaces a bunch of words before it with the same ones but without the deleted character (instead of just replacing the deleted character with an empty Slice.)

Ideally, our code shouldn’t break in these circumstances, but is there a way to make ProseMirror do the more reasonable thing (just replacing the deleted character with an empty Slice)?

Thanks!

Do you have a way reproduce this? In principle, ProseMirror does a diff of the old and updated content and creates a minimal change, so I’m not sure how/when this would happen. Some IME systems (especially Android virtual keyboards) sometimes randomly delete a bunch of text and reinsert it, but those would only be visible if they end up dispatched as separate ProseMirror view updates, which the library tries to avoid, and which, from your mentioning of this being a single replace step, doesn’t seem to match what you describe.

I tried to make a minimal repro but I can’t get it to reproduce :')

However, I’ve boiled it down to something in the 1.23.6 update in prosemirror-view. It seems there was changes on how the DOM is detected to be dirty, and this codebase might have some of that, so I’m investigating.

Okay, I finally found what causes it – and no, it seems it’s not specific to that prosemirror-view version. Basically, when there’s newline (\n) characters inside text nodes inside paragraphs that are imported raw (not from a DOM), ProseMirror seems to try to remove them when editing it. This seems something ProseMirror could have better safety around. For example, it seems that this isn’t detected when calling Node.check(). At the very least, if ProseMirror had thrown a console.warn about it, it would’ve saved me a lot of time. :slight_smile:

Repro: CodeSandbox

My next steps then are making sure that instead of having \n, they get split into separate paragraphs. (This happened because the ProseMirror JSON was generated by the backend)

Ugh, it seems that wasn’t what caused the backspace issue specifically, and I’m struggling to create a minimal reproduction. Back to prosemirror-view 1.23.5, I guess.