Skip to content

[lexical-list] Bug Fix: splicing a block into a list keeps its text formatting - #9034

Closed
LeSingh1 wants to merge 1 commit into
meta:mainfrom
LeSingh1:list-splice-keep-block-formatting
Closed

LeSingh1 wants to merge 1 commit into
meta:mainfrom
LeSingh1:list-splice-keep-block-formatting

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

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:

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.

…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.
@vercel

vercel Bot commented Aug 9, 2026

Copy link
Copy Markdown

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

@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 Aug 9, 2026
@LeSingh1

Copy link
Copy Markdown
Contributor Author

Consolidated into #9050 with the other PRs that share this defect, per @etrepum's note on #9027 and @mayrang's on #9035. Same fix and same tests, one review.

@LeSingh1 LeSingh1 closed this Aug 10, 2026
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.

1 participant