TeemuKoivisto / prosemirror-dev-toolkit

Injectable developer tools for ProseMirror rich-text editors implemented in Svelte and TypeScript.
https://teemukoivisto.github.io/prosemirror-dev-toolkit/
MIT License
116 stars 6 forks source link

Html dependency is slow with large images. #81

Closed AlansCodeLog closed 2 weeks ago

AlansCodeLog commented 1 month ago

I was running into a weird issue with my editor where I pasted a large image (src set to a very large base64 string) and when I changed my selection the editor would freeze. It would get stuck in this loop in the html dependency. I'm pretty sure it's because of this condition of the while loop. I would submit a pull request but it looks like it hasn't been updated in 8 years...

https://github.com/max-mapper/commonjs-html-prettyprinter/blob/0717eb216ebcc67399ca3c0406e5c03a77f7e761/lib/html.js#L340

Not familiar with what it could be replaced with that is fast, but it necessary to call it on every selection change? Could there be an option to disable it or could it be done some other way? I was thinking maybe as a slice and using it's toJSON. That is after all what one would have access to if writing an editor.

TeemuKoivisto commented 3 weeks ago

Hey @AlansCodeLog , thanks for the report. I was away last week so didn't have a chance to look into this.

My first idea is to debounce the HTML generation and/or put it inside a worker so that the main UI thread won't jank. I'll see when I have time to do a first proto.

AlansCodeLog commented 2 weeks ago

No problem.

I don't think debouncing will work as it will just delay the freezing. Maybe conversion could be defered until the user views the history step in the tab.

Using a webworker will help, but it will probably need to be terminated if it runs too long, and some alternative shown.

TeemuKoivisto commented 2 weeks ago

Okay I made a fix with version 1.1.8, can you @AlansCodeLog try it locally and see whether it works? I just decided to truncate the src tags, seemed the easiest solution for now.

I'll later publish an extension update

AlansCodeLog commented 2 weeks ago

Simplest solution is sometimes the best! :smile:

Works well, no more freezing or interfering with editor performance, and opening selection history entries is fast now. The doc diffs are now the slower entries, but I think that's to be expected. It's all usable now at least.

Thank you!