Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] InputRules plugin errors if replaceable text is inserted very quickly #1508

Closed
jrpat opened this issue Feb 13, 2025 · 1 comment
Closed

Comments

@jrpat
Copy link

jrpat commented Feb 13, 2025

Very simple repro, you can see it on the ProseMirror.net homepage demo.

Focus the editor (for the exact error below, I put it at the end of the text), run the following code in devtools…

document.execCommand("insertText", false, "This is a test...")

…and you'll get an error:

prosemirror.js:1 Uncaught RangeError: Position 81 out of range
    at k.resolve (prosemirror.js:1:13673)
    at k.resolveCached (prosemirror.js:1:14052)
    at N.resolve (prosemirror.js:1:16564)
    at ft.insertText (prosemirror.js:1:83263)
    at ri.handler (prosemirror.js:1:185603)
    at ii (prosemirror.js:1:186335)
    at kt.handleTextInput (prosemirror.js:1:185856)
    at prosemirror.js:1:172147
    at EditorView.someProp (prosemirror.js:1:179785)
    at Io (prosemirror.js:1:172116)

In this case the ri.handler line is this line in the stringHandler function in inputrules.ts

This might seem contrived, but I stumbled on it debugging a failure in one of our automated tests which uses Playwright. I'm not sure if they are using execCommand exactly, or just simulating keystrokes very quickly, but the result is the same.

I didn't have time to dive into exactly what the root cause is, but I suspect it'll be obvious[-ish] to someone with more context about the plugin.


💛 ProseMirror is one of the most well-engineered libraries I've ever used. It's reliable and flexible - a joy to work with. And I've learned a lot from spelunking in the source, which is remarkably easy to follow given the complexity of the problem space. Thanks for all the time, energy, and good taste you've put into it!

@jrpat jrpat changed the title [Bug] InputRules plugin errors if replacement text is inserted very quickly [Bug] InputRules plugin errors if replaceable text is inserted very quickly Feb 13, 2025
@marijnh
Copy link
Member

marijnh commented Feb 14, 2025

Thanks for reporting that. Attached patch should address it.

And also thanks for the kind words! I worked hard on the design and it's great to hear when someone appreciates it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants