#6768 fix to avoid infinite markdown shortcut matchers run #6778
+15
−2
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.
Issue #6768 happens because of emoji markdown shortcut. It has conditional replacement which was not really supported for shortcuts:
lexical/packages/lexical-playground/src/plugins/MarkdownTransformers/index.ts
Lines 105 to 108 in 07ca5c8
lexical/packages/lexical-playground/src/plugins/MarkdownShortcutPlugin/index.tsx
Line 15 in 07ca5c8
Another alternative would be to update emoji RegExp to match exact emoji names and instead of having
:([a-Z0-9]):
it'd be:(smile|sad|happy|...|joy):
. The problem is that with current emoji-list that regex is 23kb long.Enable conditional replacement (this PR). The reason it ran infinitely is because once we find match we call
textNode.splitText(matchOffset)
to extract text node that should be replaced:lexical/packages/lexical-markdown/src/MarkdownShortcuts.ts
Lines 174 to 181 in 07ca5c8
Even if we don't replace anything, it still causes full update cycle which triggers another transformers run. One thing is whether we should even call update cycle for unused result of
.splitText
(cc @zurfyx) given split nodes will reconcile back to a single text node. But on top of it, we don't really need to run any shortcuts logic if selection itself hasn't changed as we only suppose to do it when user types (i.e. selection moves).Another (more minor) issue was in emoji regex that should ensure we only attempt to run matcher against end of node's text
Test plan
Tests + sanity check