Skip to content

[lexical-list] Bug Fix: continue split-list numbering from the item's value, not its index - #8913

Merged
etrepum merged 1 commit into
facebook:mainfrom
LeSingh1:fix/list-restore-numbering-nested
Aug 5, 2026
Merged

[lexical-list] Bug Fix: continue split-list numbering from the item's value, not its index#8913
etrepum merged 1 commit into
facebook:mainfrom
LeSingh1:fix/list-restore-numbering-nested

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Description

$getNewListStart computes the split-off list's start from the item's position:

return list.getStart() + listItem.getIndexWithinParent();

Index is not the rendered number. updateChildrenListItemValue deliberately does not advance the counter for a list item that only wraps a nested list, so index and value diverge as soon as the list contains a sublist. Every nested sublist before the split point inflates the computed start by one.

Pressing Enter on an empty item in a list with a preceding sublist therefore produces 1, 2, <paragraph>, 4, 5 — the number 3 is skipped.

Returning listItem.getValue() uses the number the split point was actually rendered with. That matches the semantics the existing flat-case test already pins down: the tail list continues at the removed item's number.

Introduced in #8092; packages/lexical-list/src/utils.ts has not been touched since.

Test plan

Before

New test in LexicalListItemNode.test.ts fails on main:

AssertionError: expected 4 to be 3
- Expected  3
+ Received  4

After

Passes. Full packages/lexical-list suite: 9 files, 120 tests passed. The existing flat-list numbering tests are unchanged. eslint, prettier and tsc --noEmit clean.

… value, not its index

## Description

With `registerList(editor, {restoreNumbering: true})`, pressing Enter on an empty
list item splits the list and the tail list is given a `start` so that numbering
continues where it left off. `$getNewListStart` computed that start as
`list.getStart() + listItem.getIndexWithinParent()`.

Index is not the same as the rendered number. `updateChildrenListItemValue`
deliberately does not advance the counter for a list item that only wraps a
nested list (`if (!$isListNode(child.getFirstChild())) value++`), because such an
item renders no marker of its own. Every nested sublist before the split point
therefore pushes the computed start one number too high, and the split-off list
skips numbers:

```
1. A
   • A.1        <- wrapper <li>, renders no number
2. B
3. <empty item, caret here, press Enter>
4. C
```

Before: the tail list starts at 4, so the document reads 1, 2, paragraph, 4, 5 —
the number 3 disappears. Expected (and what the flat case already does): the tail
list starts at 3.

`ListItemNode.getValue()` is exactly the rendered number that
`updateChildrenListItemValue` maintains, so using it fixes the nested case and is
identical to the old expression for a flat list.

## Test plan

### Before

New unit test in `LexicalListItemNode.test.ts` fails on `main`:

```
FAIL  Option Enabled: Preserves numbering when a nested sublist precedes the split
AssertionError: expected 4 to be 3 // Object.is equality

- Expected
+ Received

- 3
+ 4
```

### After

`pnpm exec vitest --project unit packages/lexical-list` passes (120 tests).
@vercel

vercel Bot commented Aug 4, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview Aug 4, 2026 3:44am
lexical-playground Ready Ready Preview Aug 4, 2026 3:44am

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 Aug 4, 2026
@etrepum
etrepum added this pull request to the merge queue Aug 5, 2026
Merged via the queue into facebook:main with commit e31913f Aug 5, 2026
110 of 112 checks passed
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.

2 participants