Skip to content

Discard empty TextNode that can creep into appendJSON - #3695

Merged
trueadm merged 5 commits into
meta:mainfrom
abelsj60:fixEmptyTextBugWhenAppendingToJSON
Jan 13, 2023
Merged

trueadm merged 5 commits into
meta:mainfrom
abelsj60:fixEmptyTextBugWhenAppendingToJSON

Conversation

@abelsj60

@abelsj60 abelsj60 commented Jan 9, 2023 •

Copy link
Copy Markdown
Contributor

If an uncollapsed selection ends or starts at the end of a line of specialized TextNodes, such as code tokens, we will get a 'blank' TextNode in $appendNodesToJSON. In other words, we'll get a TextNode with a text length of 0 ('').

We do not want empty TextNodes, per @trueadm. He calls it an anti-pattern.

So, this PR filters the occasional empty TextNode out of JSON, should it appear.

I am not filtering it out of the sibling function, $appendNodesToDOM, however, as this can be handled via the exportDOM method instead. It is a more flexible method than exportJSON, so can be leveraged a little more surgically.

Filtering could be added to the $appendNodesToDOM method, however, it might be a little more involved. You might have to add a line break (a br?). I was very ginger about function, as I didn't want to break half the planet by accident.

I encountered this problem while building a LinedCodeNode. This PR is 2/2 that will let it work without patches.

-j

@vercel

vercel Bot commented Jan 9, 2023 •

Copy link
Copy Markdown

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

Name Status Preview Comments Updated
lexical ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 10, 2023 at 4:40PM (UTC)
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 10, 2023 at 4:40PM (UTC)

@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 Jan 9, 2023
@abelsj60 abelsj60 changed the title Discard empty text node that creeps into append JSON Discard empty TextNode that can creep into append JSON Jan 9, 2023
@abelsj60 abelsj60 changed the title Discard empty TextNode that can creep into append JSON Discard empty TextNode that can creep into appendJSON Jan 9, 2023
@trueadm
trueadm merged commit eb573a0 into meta:main Jan 13, 2023
@abelsj60
abelsj60 deleted the fixEmptyTextBugWhenAppendingToJSON branch January 16, 2023 18:08
This was referenced Jan 24, 2023

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — 666246bc Deployed Jan 10, 2023 by vercel[bot]
Preview – lexical — 666246bc Deployed Jan 10, 2023 by vercel[bot]
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.

3 participants