Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lexical] Bug Fix: removeText for token text nodes #6688

Conversation

adrianmxb
Copy link
Contributor

@adrianmxb adrianmxb commented Oct 1, 2024

Description

This PR fixes an issue where text nodes in token mode were not being deleted properly when partially removed. According to the documentation, token nodes should be immutable and should be deleted as a whole. However, the current behaviour allowed partial deletion of the text within a token node, resulting in an unexpected mutation into a non-token node.

Describe the changes in this pull request

  1. In fixText added another condition treating a token node similiar to an empty text node, effectively removing the node.
  2. Consistent Return: fixText now always returns a node, eliminating the need for the || operator in assignments like firstNode = fixText(firstNode, del) || firstNode;. This simplifies the code and prevents potential undefined errors.

Closes #6687

Test plan

Before

CleanShot 2024-10-01 at 18 28 12

After

CleanShot 2024-10-01 at 18 27 14

Copy link

vercel bot commented Oct 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 1, 2024 5:44pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 1, 2024 5:44pm

@facebook-github-bot facebook-github-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 Oct 1, 2024
Copy link

github-actions bot commented Oct 1, 2024

size-limit report 📦

Path Size
lexical - cjs 29.82 KB (0%)
lexical - esm 29.67 KB (0%)
@lexical/rich-text - cjs 38.42 KB (0%)
@lexical/rich-text - esm 31.51 KB (0%)
@lexical/plain-text - cjs 37.01 KB (0%)
@lexical/plain-text - esm 28.9 KB (0%)
@lexical/react - cjs 40.17 KB (0%)
@lexical/react - esm 32.97 KB (0%)

@adrianmxb adrianmxb marked this pull request as draft October 1, 2024 17:40
@etrepum
Copy link
Collaborator

etrepum commented Oct 1, 2024

The important part to write is the test coverage, otherwise it's hard to confirm that the bug is fixed and a regression is likely to happen again. I started on some of it in #6690

@adrianmxb
Copy link
Contributor Author

Closed in favour of #6690

@adrianmxb adrianmxb closed this Oct 1, 2024
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: removeText misbehaves for text nodes in token mode
3 participants