Skip to content

[lexical-link] Bug Fix: Enable autolink matching when it unlinked#8165

Merged
etrepum merged 7 commits intofacebook:mainfrom
levensta:check-valid-unlinked-autolink
Mar 2, 2026
Merged

[lexical-link] Bug Fix: Enable autolink matching when it unlinked#8165
etrepum merged 7 commits intofacebook:mainfrom
levensta:check-valid-unlinked-autolink

Conversation

@levensta
Copy link
Copy Markdown
Contributor

Description

Previously, it was possible to enter invalid characters in the text of an unlinked AutoLinkNode, which made the link invalid. The fix activates parsing of valid links in AutoLinkNode if they are marked as unlinked

Test plan

Before

Screen.Recording.2026-02-24.at.02.14.48.mov

After

Screen.Recording.2026-02-24.at.02.16.35.mov

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Mar 2, 2026 8:01pm
lexical-playground Ready Ready Preview, Comment Mar 2, 2026 8:01pm

Request Review

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 23, 2026
Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this fixes the whole problem, e.g. if you have an unlinked AutoLinkNode and add a decorator like date or emoji it will split the AutoLinkNode instead of destroying any of them

@levensta
Copy link
Copy Markdown
Contributor Author

I'm not sure this fixes the whole problem, e.g. if you have an unlinked AutoLinkNode and add a decorator like date or emoji it will split the AutoLinkNode instead of destroying any of them

If during transformation one of the child nodes is not a TextNode or is not simple, the link will be destroyed. I added a test with emoji

@levensta
Copy link
Copy Markdown
Contributor Author

The tests are failing for the second time in a specific job e2e-tests / windows (22.x, chromium, rich-text, legacy-events) / e2e-test. I don't understand what the problem might be yet, maybe it's worth marking the tests as flaky or rewriting them as unit tests in LexicalAutoLinkExtension

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Feb 25, 2026

I'm not sure either without looking a lot more closely, which is hard for me since I don't have a windows computer to test with. unit tests would be fine, it's unclear if marking them as flaky would be a sufficient workaround. Really depends on what kind of timing issue it is.

@levensta

This comment was marked as outdated.

@levensta

This comment was marked as outdated.

@levensta
Copy link
Copy Markdown
Contributor Author

levensta commented Feb 26, 2026

Well, it took some time to figure out that the LEGACY_EVENTS variable disables the beforeInput event, and this has nothing to do with the version of Playwright 😅

The truth turned out to be that even in the current version of lexical, without changes from this PR, there is a problem that this test revealed, and it also occurs on MacOS

_Screen.Recording.2026-02-27.at.01.23.01.mov

https://playground.lexical.dev/?disableBeforeInput=true

@levensta
Copy link
Copy Markdown
Contributor Author

I also see that in LEGACY_EVENTS mode, there is a delay between key type/press events, which may have affected the fact that the tests passed successfully on other operating systems
https://github.com/facebook/lexical/blob/main/packages/lexical-playground/__tests__/utils/index.mjs#L109-L114

I checked locally that the node transform handler is called once in both cases

Comment on lines +756 to +760
test('Unlinked the autolink should not destruct if add non-spacing text in front or right after it', async ({
page,
isPlainText,
}) => {
test.skip(isPlainText || LEGACY_EVENTS);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a result, the current changes in this PR do not bring anything new to this scenario. It already fails in prod in legacy_events mode, so I added a condition to skip the test #8165 (comment)

Tests directly related to the new behavior are written below.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think legacy events are probably vestigial since we don't support browser versions that old anymore. AFAICT Chrome 60+ does not need it, and we don't support anything older than Chrome 86.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good reason to remove legacy-events tests jobs. At the same time, I could refactor the tests and remove all stubs for legacy-events mode.

I can work on this and submit a separate PR

@levensta levensta requested a review from etrepum February 28, 2026 20:21
Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just adding some suggestions to the test names to make them a bit easier to understand, I'll go ahead and apply these changes directly

@etrepum etrepum added this pull request to the merge queue Mar 2, 2026
Merged via the queue into facebook:main with commit ff11745 Mar 2, 2026
42 checks passed
@etrepum etrepum mentioned this pull request Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants