Repository navigation
Conversation
…ormatting
## Description
`ListNode.splice` wraps any non-`ListItemNode` it is given in a list item. For
a block-level node it does not put the block inside the item — a list item is
an inline-level container, so that would be invalid — it replaces it with its
plain text:
```ts
listItemNodesToInsert[i] = this.createListItemNode().append(
$isElementNode(node) && !($isListNode(node) || node.isInline())
? $createTextNode(node.getTextContent())
: node,
);
```
`getTextContent()` returns a string, so every text format and style on the
block's children is discarded and inline nodes are flattened: a paragraph
holding **bold** text and a link becomes one unformatted TextNode with the
link gone.
The package already performs this exact conversion in two other places, and
both keep the children. `$createListOrMerge` does
`append(listItem, node.getChildren())`, and `ListItemNode.append` unwraps a
block it can merge with by re-appending `node.getChildren()`. `ListNode.splice`
is the only one that stringifies.
This unwraps the block into its own children instead. Non-block and inline
nodes take the same path as before, and a `ListNode` child is still left alone.
## Test plan
`npx vitest run packages/lexical-list/src/__tests__/unit/ListSpliceKeepsFormatting.test.ts`
(The natural test file, `LexicalListNode.test.ts`, is already being edited by
an open PR, so the repro lives in its own file.)
### Before
```
❯ |unit| packages/lexical-list/src/__tests__/unit/ListSpliceKeepsFormatting.test.ts (2 tests | 2 failed) 14ms
× keeps the text formats of the block it unwraps 12ms
× keeps an inline node of the block it unwraps 2ms
FAIL ... > keeps the text formats of the block it unwraps
AssertionError: expected [ 'boldstyled' ] to deeply equal [ 'bold', 'styled' ]
- Expected
+ Received
[
- "bold",
- "styled",
+ "boldstyled",
]
```
### After
```
Test Files 1 passed (1)
Tests 2 passed (2)
```
Also green:
- `npx vitest run packages/lexical-list packages/lexical-markdown packages/lexical-mdast packages/lexical-react packages/lexical-clipboard` — 52 files, 925 tests
- `E2E_BROWSER=chromium npx playwright test --project=chromium List.spec.mjs` — 36 passed
Only chromium was exercised locally for the e2e run.
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 9, 2026 05:54
|
@LeSingh1 is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ListNode.splicewraps any non-ListItemNodeit is given in a list item. Fora block-level node it does not put the block inside the item — a list item is
an inline-level container, so that would be invalid — it replaces it with its
plain text:
getTextContent()returns a string, so every text format and style on theblock's children is discarded and inline nodes are flattened: a paragraph
holding bold text and a link becomes one unformatted TextNode with the
link gone.
The package already performs this exact conversion in two other places, and
both keep the children.
$createListOrMergedoesappend(listItem, node.getChildren()), andListItemNode.appendunwraps ablock it can merge with by re-appending
node.getChildren().ListNode.spliceis the only one that stringifies.
This unwraps the block into its own children instead. Non-block and inline
nodes take the same path as before, and a
ListNodechild is still left alone.Test plan
npx vitest run packages/lexical-list/src/__tests__/unit/ListSpliceKeepsFormatting.test.ts(The natural test file,
LexicalListNode.test.ts, is already being edited byan open PR, so the repro lives in its own file.)
Before
After
Also green:
npx vitest run packages/lexical-list packages/lexical-markdown packages/lexical-mdast packages/lexical-react packages/lexical-clipboard— 52 files, 925 testsE2E_BROWSER=chromium npx playwright test --project=chromium List.spec.mjs— 36 passedOnly chromium was exercised locally for the e2e run.