[lexical][@lexical/link] Bug Fix: Fix infinite transform loop in AutoLinkPlugin#8070
Merged
etrepum merged 7 commits intofacebook:mainfrom Jan 13, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…wrapping logic for textNode placement
…nwrapping logic and clarify TLD checks
Collaborator
|
It looks like this PR is failing e2e tests |
… checks for link unwrapping logic
Contributor
Author
|
Ok, just fixed it |
etrepum
reviewed
Jan 11, 2026
packages/lexical-link/src/__tests__/unit/LexicalAutoLinkExtension.test.ts
Outdated
Show resolved
Hide resolved
packages/lexical-link/src/__tests__/unit/LexicalAutoLinkExtension.test.ts
Outdated
Show resolved
Hide resolved
etrepum
reviewed
Jan 12, 2026
packages/lexical-link/src/__tests__/unit/LexicalAutoLinkExtension.test.ts
Outdated
Show resolved
Hide resolved
packages/lexical-link/src/__tests__/unit/LexicalAutoLinkExtension.test.ts
Outdated
Show resolved
Hide resolved
Contributor
Author
|
Plesae do check again, just push another one. |
etrepum
reviewed
Jan 13, 2026
Collaborator
etrepum
left a comment
There was a problem hiding this comment.
This looks good but let's clean up the tests to use assert, should reduce a lot of the code
Comment on lines
+68
to
+74
| const paragraph = root.getFirstChild(); | ||
|
|
||
| // Verify paragraph exists (not empty root) and is an ElementNode | ||
| expect(paragraph).not.toBeNull(); | ||
| expect($isParagraphNode(paragraph)).toBe(true); | ||
|
|
||
| const paragraphNode = paragraph as ParagraphNode; |
Collaborator
There was a problem hiding this comment.
vitest has an assert function that lets you write expectations that will also refine the types so you don't need to do any casting
Suggested change
| const paragraph = root.getFirstChild(); | |
| // Verify paragraph exists (not empty root) and is an ElementNode | |
| expect(paragraph).not.toBeNull(); | |
| expect($isParagraphNode(paragraph)).toBe(true); | |
| const paragraphNode = paragraph as ParagraphNode; | |
| const paragraphNode = root.getFirstChild(); | |
| assert($isParagraphNode(paragraphNode), 'first root child must be a ParagraphNode'); |
…xtNode verification
Contributor
Author
|
oke cool, now another one pushed. |
etrepum
approved these changes
Jan 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Fixes infinite transform loop in
AutoLinkPluginwhen initializing content with patterns like#1234.Anotherwhere the matcher matches#1234but the text continues with a period (.). The period after the match causes boundary validation to fail, which triggers link unwrapping, which re-triggers the transform, creating an infinite loop.Current Behavior
When initializing editor content with text like
#1234.Anotherwhere#1234matches a link matcher but is followed by a period, the AutoLink transform enters an infinite loop:#1234and creates anAutoLinkNode.Anotherfollows the matchChanges in this PR
Made the
registerAutoLinktransform idempotent by adding guards to prevent re-processing nodes that are already part of anAutoLinkNode:$handleLinkCreation: Added early return if any input node is already linked, and skip creating a new link if matching nodes are already part of anAutoLinkNode.handleBadNeighbors: Added early return iftextNodeis already part of anAutoLinkNode, and added validation checks before appending to siblings to ensure nodes are still siblings and the combined text would still form a valid link.registerAutoLinktransform: Added check to skip processing iftextNodeis already part of anAutoLinkNode.These changes ensure the transform only processes nodes that actually need link creation/editing, preventing infinite loops while maintaining correct link behavior.
Testing
registerAutoLink does not cause infinite transform loop with #1234.Anotherthat reproduces the issue and verifies the fixCloses #7646