Skip to content

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

Open
levensta wants to merge 6 commits intofacebook:mainfrom
levensta:check-valid-unlinked-autolink
Open

[lexical-link] Bug Fix: Enable autolink matching when it unlinked#8165
levensta wants to merge 6 commits intofacebook:mainfrom
levensta:check-valid-unlinked-autolink

Conversation

@levensta
Copy link
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

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 Feb 28, 2026 7:56pm
lexical-playground Ready Ready Preview, Comment Feb 28, 2026 7:56pm

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
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
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
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
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
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
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
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.

@levensta levensta requested a review from etrepum February 28, 2026 20:21
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