Skip to content

[lexical-list] Bug Fix: keep the numbering when a block is inserted between list items - #9021

Closed
LeSingh1 wants to merge 1 commit into
meta:mainfrom
LeSingh1:list-split-numbering-insert-after
Closed

LeSingh1 wants to merge 1 commit into
meta:mainfrom
LeSingh1:list-split-numbering-insert-after

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Description

ListItemNode.insertAfter splits its list when the node being inserted is not
a ListItemNode — that is how a page break, horizontal rule, image, or any
other block ends up between two items. The trailing items are moved into
$copyNode(listNode), which carries the original list's start, so the
ListNode $transform renumbers them from that start and the list visibly
restarts at 1 after the inserted block.

$getNewListStart already exists for exactly this: it is the helper
$handleListInsertParagraph uses to continue the numbering across a split, and
it returns the number the split point was rendered with (the item's value, not
its index, so nested-list wrapper items do not skew it).

This applies it to the insertAfter split, using the first item that moves
into the new list. It is scoped to listType === 'number', the only list type
where start is meaningful, so bullet and check lists keep the start they
copy today.

Refs #7032

Test plan

npx vitest run packages/lexical-list/src/__tests__/unit/Issue7032Repro.test.ts

(The natural test file, LexicalListItemNode.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/Issue7032Repro.test.ts (3 tests | 2 failed) 14ms
     × inserting a block between list items continues the numbering 11ms
     × a list that does not start at 1 continues from the split point 1ms

 FAIL  ... > inserting a block between list items continues the numbering
AssertionError: expected 1 to be 2 // Object.is equality

- Expected
+ Received

- 2
+ 1

 FAIL  ... > a list that does not start at 1 continues from the split point
AssertionError: expected 5 to be 7 // Object.is equality

- Expected
+ Received

- 7
+ 5

After

 Test Files  1 passed (1)
      Tests  3 passed (3)

Also green:

  • npx vitest run packages/lexical-list — 11 files, 128 tests
  • npx vitest run packages/lexical-markdown packages/lexical-mdast packages/lexical-react packages/lexical-clipboard — 41 files, 798 tests
  • E2E_BROWSER=chromium npx playwright test --project=chromium List.spec.mjs — 36 passed
  • E2E_BROWSER=chromium npx playwright test --project=chromium HorizontalRule.spec.mjs — 15 passed
    (this is the suite that exercises inserting a rule inside a list)

Only chromium was exercised locally for the e2e runs.

…etween list items

## Description

`ListItemNode.insertAfter` splits its list when the node being inserted is not
a `ListItemNode` — that is how a page break, horizontal rule, image, or any
other block ends up between two items. The trailing items are moved into
`$copyNode(listNode)`, which carries the *original* list's `start`, so the
`ListNode` `$transform` renumbers them from that start and the list visibly
restarts at 1 after the inserted block.

`$getNewListStart` already exists for exactly this: it is the helper
`$handleListInsertParagraph` uses to continue the numbering across a split, and
it returns the number the split point was rendered with (the item's value, not
its index, so nested-list wrapper items do not skew it).

This applies it to the `insertAfter` split, using the first item that moves
into the new list. It is scoped to `listType === 'number'`, the only list type
where `start` is meaningful, so bullet and check lists keep the `start` they
copy today.

Refs meta#7032

## Test plan

`npx vitest run packages/lexical-list/src/__tests__/unit/Issue7032Repro.test.ts`

(The natural test file, `LexicalListItemNode.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/Issue7032Repro.test.ts (3 tests | 2 failed) 14ms
     × inserting a block between list items continues the numbering 11ms
     × a list that does not start at 1 continues from the split point 1ms

 FAIL  ... > inserting a block between list items continues the numbering
AssertionError: expected 1 to be 2 // Object.is equality

- Expected
+ Received

- 2
+ 1

 FAIL  ... > a list that does not start at 1 continues from the split point
AssertionError: expected 5 to be 7 // Object.is equality

- Expected
+ Received

- 7
+ 5
```

### After

```
 Test Files  1 passed (1)
      Tests  3 passed (3)
```

Also green:

- `npx vitest run packages/lexical-list` — 11 files, 128 tests
- `npx vitest run packages/lexical-markdown packages/lexical-mdast packages/lexical-react packages/lexical-clipboard` — 41 files, 798 tests
- `E2E_BROWSER=chromium npx playwright test --project=chromium List.spec.mjs` — 36 passed
- `E2E_BROWSER=chromium npx playwright test --project=chromium HorizontalRule.spec.mjs` — 15 passed
  (this is the suite that exercises inserting a rule inside a list)

Only chromium was exercised locally for the e2e runs.
@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