Skip to content

[lexical-list] Feature: Add the createListItemNode method to the ListNode and use it for children normalization#8427

Merged
etrepum merged 11 commits intofacebook:mainfrom
levensta:normalize-children
May 1, 2026
Merged

[lexical-list] Feature: Add the createListItemNode method to the ListNode and use it for children normalization#8427
etrepum merged 11 commits intofacebook:mainfrom
levensta:normalize-children

Conversation

@levensta
Copy link
Copy Markdown
Contributor

@levensta levensta commented Apr 30, 2026

Description

Follow-up #8213

Classes that extend ListNode can use the parent after method from the conversion function in importDOM. To ensure that child normalization works correctly, createListItemNode method has been added to the ListNode class, which can be overridden in subclasses

Test plan

Before

Insert relevant screenshots/recordings/automated-tests

After

Insert relevant screenshots/recordings/automated-tests

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 30, 2026

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment May 1, 2026 9:58pm
lexical-playground Ready Ready Preview, Comment May 1, 2026 9:58pm

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 Apr 30, 2026
@levensta
Copy link
Copy Markdown
Contributor Author

levensta commented Apr 30, 2026

Since a copy of ListItemNode is now used for normalization, the default dir="ltr" attribute was missing from the test. I think this is a positive change, although the normalized listitem does not affect the direction of the list, so I just updated the test

image

Comment thread packages/lexical-list/src/utils.ts Outdated
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.

Maybe a better solution to solve the problem at hand is to give ListNode a createListItem(): ListItemNode { return $createListItem(); } method by subclasses. I think this is probably the actual behavior you're trying to achieve here (also the splice method could use this)?

Comment thread packages/lexical-list/src/LexicalListNode.ts Outdated
@levensta
Copy link
Copy Markdown
Contributor Author

I don't quite understand why the ListItemNode class needs a method that will create an instance of the same class. In this case, it is important to create a copy of the same instance that is already contained in the ListNode

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Apr 30, 2026

That was a typo on my part, edited to correct ListItem to ListNode

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Apr 30, 2026

I'd like more context about why it is important to create a copy of some arbitrary other ListItemNode and why the ListNode subclass wouldn't have enough information to create the correct type of ListItemNode wrapper

@levensta
Copy link
Copy Markdown
Contributor Author

In actually, with the createListItemNode method, ListNode will be able to create ListItem of the desired type, since this method can be overridden. Since the types indicate that a ListNode might be null during normalizing list items, I included a fallback that creates a copy

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented May 1, 2026

There's already ListItemNode.createParentElementNode() which can be used to create a parent ListNode and be overridden. I haven't audited it to see if it's used everywhere it should be, but that would solve the missing ListNode problem in an extensible way without copy heuristics.

@levensta levensta changed the title [lexical-list] Bug Fix: Wrap the node in a ListItemNode copy during normalization [lexical-list] Feature: Add the createListItemNode method to the ListNode and use it for children normalization May 1, 2026
@etrepum etrepum enabled auto-merge May 1, 2026 22:20
@etrepum etrepum added this pull request to the merge queue May 1, 2026
Merged via the queue into facebook:main with commit fa5523a May 1, 2026
41 checks passed
etrepum added a commit to mayrang/lexical that referenced this pull request May 2, 2026
…stNode and use it for children normalization (facebook#8427)

Co-authored-by: Bob Ippolito <bob@redivi.com>
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