Cache rendered mathjax to avoid stalling when editing plaintext #3828
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#3827 deals with stalling when editing in the richtext editor's mathjax overlay editor. But when the plaintext editor is changed, all the mathjax custom element components are recreated* and thus rerendered on each change.
This can be much slower since now all the mathjax expressions in the field are re-rendered even if none of them were changed
The fix proposed here is to add and use lru-cache (an existing indirect dep) to cache the rendered svg. A max cache size of 10 is chosen to limit memory use, and should account for most normal usecases with <10 mathjax exprs per field
*this seems to have been noted already in #1502 (comment). it's also why the debouncing within the component has no effect here