Fix sending of emptystring class for Prosemirror decoration #1004
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.
Prosemirror does not handle emptystring classes well for decorations when the decoration applies to a range that has other decorations. For example, both a spellchecking plugin and the tiptap highlighting plugin.
See this debugger screenshot in prosemirror showing the code that merges decorations together before they're applied. There are two decorations - one from a spellchecker, and one from the Highlight plugin that has no class because the specific range did not receive any specific highlight:
The above results in a string like
"spellcheck-error "
, which is then re-split by prosemirror into an array["spellcheck-error", ""]
. This is in turn fed intoHTMLElement.classList.add(...)
, which throws an error when it receives emptystring:However, there's no reason to send an empty decoration to prosemirror at all, so this change elects to omit such decorations entirely. This both fixes the issue at hand, and also slightly improve performance.