Skip to content

[lexical-y] Bug Fix: Number the list items of a freshly bound editor right away when the document holds a block with a named slot - #9573

Closed
zurfyx wants to merge 1 commit into
mainfrom
zurfyx/y-list-value-slot-read
Closed

zurfyx wants to merge 1 commit into
mainfrom
zurfyx/y-list-value-slot-read

Conversation

@zurfyx

@zurfyx zurfyx commented Oct 30, 2026

Copy link
Copy Markdown
Member

Description

Reported downstream. In an editor freshly bound to a document that holds a block with a named slot, every ordered list item was numbered 1: getValue() returned 1, <li value="1"> was rendered, and a custom start was ignored. A fresh readYState of the same document numbered them correctly, and so did a peer once it received a remote change. The bug was introduced by #9510.

A list item's value (and indent) is derived, not stored. After each read, the binding renumbers the lists in a refresh update of its own (flushRefresh). Reads run without transforms.

Since #9510, the binding becomes active after the first read has committed, so the editor turns editable then. In an editor that uses named slots, LexicalEditor.setEditable re-renders in an update of its own ($fullReconcile). That update was still pending when the read's after() called flushRefresh. The editor was therefore not idle, and the refresh waited for runPending a microtask later. Until then the editor showed the read without its derived fields. Before #9510 the binding was active before the read, so that update committed ahead of the read (commitPending).

The same deferral happened after a remote read that turns the binding read only (checkUnknownTypes → setEditable(false)).

flushRefresh now commits the local updates still pending or queued (commitPending) when it is called outside any update and the editor is not idle. The refresh then commits right away. The order is the same as before: those updates commit first, then the refresh. But it now happens before the binding's call returns.

Inside an update (a nested read's after(), a listener phase), nothing changes. If listeners keep making updates past MAX_PENDING_COMMITS, the existing deferred path still applies. Invariant: once a read's work is done, the editor shows the derived fields the read left, as a fresh reader of the document does.

Test plan

regressions/ListValuesAfterRead.test.ts:

  • Docs: no slot block, a declared slot or a component (decorator) slot before or after two lists (one starting at 9), and a nested list with a slot block.
  • Bind styles: a host's YBinding start and initialize on a mounted editor, YCollabExtension with synced, and YCollabExtension initialized after mount.
  • Checks, made right after the call returns with nothing awaited:
    • getValue(), <li value> and the list starts;
    • every field a class declares derived, against an editor with no binding;
    • the whole editor state, against readYState.
  • A remote change that adds an item and turns the binding read only.
  • Undo and redo steps, and an undo burst, against readYState.

The YCollabExtension cases pass before the fix as well, because mounting the root after the build commits the pending update. The undo test fails before the fix only at its open check.

Before

$ pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/regressions/ListValuesAfterRead.test.ts
     × binding: a component slot after the lists 99ms
     × binding: a component slot before the lists 15ms
     × binding: a declared slot after the lists 16ms
     × binding: a declared slot before the lists 15ms
     × binding: a nested list and a declared slot 15ms
     ✓ binding: no slot block 12ms
     ✓ extension: a component slot after the lists 20ms
     ...
     ✓ extension-then-sync: no slot block 13ms
     × the derived fields it changes are shown right away 18ms
     × each step shows the derived fields a fresh reader does 18ms
AssertionError: expected [ 1, 1, 1, 1, 1, 1 ] to deeply equal [ 1, 2, 3, 9, 10, 11 ]
      Tests  7 failed | 13 passed (20)

After

$ pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/regressions/ListValuesAfterRead.test.ts
 ✓ |unit| packages/lexical-y/src/__tests__/unit/regressions/ListValuesAfterRead.test.ts (20 tests) 433ms
      Tests  20 passed (20)
  • @lexical/y unit suite: 166 files pass (7502 passed, 46 expected fail, 4 skipped).
  • lexical unit suite: 102 files, 2390 passed.
  • In-repo fuzz (Fuzz.test.ts seeds 1..3000 and gc seeds 1..600, plus SlotsFuzz, ConcurrentShapesFuzz, FollowUpFuzz, NestedFuzz, FuzzReplay, BlockIdFuzzSeeds at their defaults): same as main (seed 2277 only, a documented limit).
  • pnpm run ci-check passes.
  • Browser and e2e tests were not run; the change is in the binding's update scheduling, covered by the jsdom unit tests above.

…right away when the document holds a block with a named slot

## Description

Reported downstream. In an editor freshly bound to a document that holds a block with a named slot, every ordered list item was numbered 1: `getValue()` returned 1, `<li value="1">` was rendered, and a custom `start` was ignored. A fresh `readYState` of the same document numbered them correctly, and so did a peer once it received a remote change. The bug was introduced by #9510.

A list item's `value` (and `indent`) is derived, not stored. After each read, the binding renumbers the lists in a refresh update of its own (`flushRefresh`). Reads run without transforms.

Since #9510, the binding becomes active after the first read has committed, so the editor turns editable then. In an editor that uses named slots, `LexicalEditor.setEditable` re-renders in an update of its own (`$fullReconcile`). That update was still pending when the read's `after()` called `flushRefresh`. The editor was therefore not idle, and the refresh waited for `runPending` a microtask later. Until then the editor showed the read without its derived fields. Before #9510 the binding was active before the read, so that update committed ahead of the read (`commitPending`).

The same deferral happened after a remote read that turns the binding read only (`checkUnknownTypes` → `setEditable(false)`).

`flushRefresh` now commits the local updates still pending or queued (`commitPending`) when it is called outside any update and the editor is not idle. The refresh then commits right away. The order is the same as before: those updates commit first, then the refresh. But it now happens before the binding's call returns.

Inside an update (a nested read's `after()`, a listener phase), nothing changes. If listeners keep making updates past `MAX_PENDING_COMMITS`, the existing deferred path still applies. Invariant: once a read's work is done, the editor shows the derived fields the read left, as a fresh reader of the document does.

## Test plan

`regressions/ListValuesAfterRead.test.ts`:
- Docs: no slot block, a declared slot or a component (decorator) slot before or after two lists (one starting at 9), and a nested list with a slot block.
- Bind styles: a host's `YBinding` start and initialize on a mounted editor, `YCollabExtension` with `synced`, and `YCollabExtension` initialized after mount.
- Checks, made right after the call returns with nothing awaited:
  - `getValue()`, `<li value>` and the list starts;
  - every field a class declares derived, against an editor with no binding;
  - the whole editor state, against `readYState`.
- A remote change that adds an item and turns the binding read only.
- Undo and redo steps, and an undo burst, against `readYState`.

The `YCollabExtension` cases pass before the fix as well, because mounting the root after the build commits the pending update. The undo test fails before the fix only at its open check.

### Before

```
$ pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/regressions/ListValuesAfterRead.test.ts
     × binding: a component slot after the lists 99ms
     × binding: a component slot before the lists 15ms
     × binding: a declared slot after the lists 16ms
     × binding: a declared slot before the lists 15ms
     × binding: a nested list and a declared slot 15ms
     ✓ binding: no slot block 12ms
     ✓ extension: a component slot after the lists 20ms
     ...
     ✓ extension-then-sync: no slot block 13ms
     × the derived fields it changes are shown right away 18ms
     × each step shows the derived fields a fresh reader does 18ms
AssertionError: expected [ 1, 1, 1, 1, 1, 1 ] to deeply equal [ 1, 2, 3, 9, 10, 11 ]
      Tests  7 failed | 13 passed (20)
```

### After

```
$ pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/regressions/ListValuesAfterRead.test.ts
 ✓ |unit| packages/lexical-y/src/__tests__/unit/regressions/ListValuesAfterRead.test.ts (20 tests) 433ms
      Tests  20 passed (20)
```

- `@lexical/y` unit suite: 166 files pass (7502 passed, 46 expected fail, 4 skipped).
- `lexical` unit suite: 102 files, 2390 passed.
- In-repo fuzz (`Fuzz.test.ts` seeds 1..3000 and gc seeds 1..600, plus `SlotsFuzz`, `ConcurrentShapesFuzz`, `FollowUpFuzz`, `NestedFuzz`, `FuzzReplay`, `BlockIdFuzzSeeds` at their defaults): same as main (seed 2277 only, a documented limit).
- `pnpm run ci-check` passes.
- Browser and e2e tests were not run; the change is in the binding's update scheduling, covered by the jsdom unit tests above.
@vercel

vercel Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
lexical Ready Ready Preview Oct 30, 2026 11:21am UTC
lexical-playground Ready Ready Preview Oct 30, 2026 11:21am UTC

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 Oct 30, 2026
@meta-code-review

meta-code-review Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 30, 2026, 11:48 AM UTC

@pkg-pr-new

pkg-pr-new Bot commented Oct 30, 2026

Copy link
Copy Markdown
lexical

npm i https://pkg.pr.new/lexical@9573

@lexical/a11y

npm i https://pkg.pr.new/@lexical/a11y@9573

@lexical/clipboard

npm i https://pkg.pr.new/@lexical/clipboard@9573

@lexical/code

npm i https://pkg.pr.new/@lexical/code@9573

@lexical/code-core

npm i https://pkg.pr.new/@lexical/code-core@9573

@lexical/code-prism

npm i https://pkg.pr.new/@lexical/code-prism@9573

@lexical/code-shiki

npm i https://pkg.pr.new/@lexical/code-shiki@9573

@lexical/compiler

npm i https://pkg.pr.new/@lexical/compiler@9573

@lexical/devtools-core

npm i https://pkg.pr.new/@lexical/devtools-core@9573

@lexical/dragon

npm i https://pkg.pr.new/@lexical/dragon@9573

@lexical/eslint-plugin

npm i https://pkg.pr.new/@lexical/eslint-plugin@9573

@lexical/extension

npm i https://pkg.pr.new/@lexical/extension@9573

@lexical/fast-check

npm i https://pkg.pr.new/@lexical/fast-check@9573

@lexical/file

npm i https://pkg.pr.new/@lexical/file@9573

@lexical/hashtag

npm i https://pkg.pr.new/@lexical/hashtag@9573

@lexical/headless

npm i https://pkg.pr.new/@lexical/headless@9573

@lexical/history

npm i https://pkg.pr.new/@lexical/history@9573

@lexical/html

npm i https://pkg.pr.new/@lexical/html@9573

@lexical/internal

npm i https://pkg.pr.new/@lexical/internal@9573

@lexical/link

npm i https://pkg.pr.new/@lexical/link@9573

@lexical/list

npm i https://pkg.pr.new/@lexical/list@9573

@lexical/mark

npm i https://pkg.pr.new/@lexical/mark@9573

@lexical/markdown

npm i https://pkg.pr.new/@lexical/markdown@9573

@lexical/mdast

npm i https://pkg.pr.new/@lexical/mdast@9573

@lexical/offset

npm i https://pkg.pr.new/@lexical/offset@9573

@lexical/overflow

npm i https://pkg.pr.new/@lexical/overflow@9573

@lexical/plain-text

npm i https://pkg.pr.new/@lexical/plain-text@9573

@lexical/react

npm i https://pkg.pr.new/@lexical/react@9573

@lexical/rich-text

npm i https://pkg.pr.new/@lexical/rich-text@9573

@lexical/selection

npm i https://pkg.pr.new/@lexical/selection@9573

@lexical/table

npm i https://pkg.pr.new/@lexical/table@9573

@lexical/tailwind

npm i https://pkg.pr.new/@lexical/tailwind@9573

@lexical/text

npm i https://pkg.pr.new/@lexical/text@9573

@lexical/utils

npm i https://pkg.pr.new/@lexical/utils@9573

@lexical/y

npm i https://pkg.pr.new/@lexical/y@9573

@lexical/yjs

npm i https://pkg.pr.new/@lexical/yjs@9573

commit: 035f17e

@meta-code-review meta-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clear write-up. Committing the updates still pending outside any update (commitPending) before the refresh keeps the binding's own refresh committing alone, in the same order as the deferred path (the pending updates first, then the refresh), only now before the call returns. Inside an update nothing changes, and the refresh still writes nothing to the shared document.

Suggestion: make the extension-then-sync case sync after mount (packages/lexical-y/src/__tests__/unit/regressions/ListValuesAfterRead.test.ts:298)

The case doesn't do what its comment (lines 248-249) describes. bind() creates the document from seed before the editor is built (line 252), so YCollabExtension's start() already reads it while buildEditorFromExtensions runs, and the binding.initialize() call returns at once because the binding is no longer pending. That is why all six of these cases pass without the fix too. The flow the docs show (packages/lexical-website/docs/collaboration/y.md: build and mount, then binding.initialize() once the provider syncs) does reproduce the bug: starting from an empty createYDoc(), mounting, then Y.applyUpdate(doc, seed) and initialize(), the item values read [1, 1, 1, 1, 1, 1] without this change and [1, 2, 3, 9, 10, 11] with it. Creating that case's document empty and applying seed after mount() would give the documented path a test that fails without the fix.

The host-binding and read-only cases do fail without the fix and pass with it, and the changeset follows .changeset/README.md (a [fix] patch entry with a Verify: paragraph).

root = mount(editor);
binding = getExtensionDependencyFromEditor(editor, YCollabExtension).output
.binding;
if (how === 'extension-then-sync') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: this case doesn't sync after mount, as the comment at lines 248-249 says. doc is created from seed before the build (line 252), so YCollabExtension's start() reads it during buildEditorFromExtensions and this initialize() returns at once (the binding is no longer pending); that is why the six extension-then-sync cases pass without the fix as well. The documented flow (an empty createYDoc(), build and mount, then Y.applyUpdate(doc, seed) and initialize()) does reproduce the bug: [1, 1, 1, 1, 1, 1] without the fix, [1, 2, 3, 9, 10, 11] with it. Creating this case's document empty and applying seed after mount() would make it a failing-before test of that path.

@zurfyx
zurfyx added this pull request to the merge queue Oct 30, 2026
zurfyx added a commit that referenced this pull request Oct 30, 2026
…s that #9573 fixed

## Description

#9573 merged, so the slot-block list numbering cells pass on main: the 179 cells marked `test.fails` for it (139 in `C1ReadEqualsFresh.test.ts`, 16 in `C1Busy.test.ts`, the 24 seeds of `CatalogSoakFuzz.test.ts`) now report as passing unexpectedly. They are plain tests again. The other expected failures (#9553, #9568, #9540, #9581) stay.

## Test plan

```
pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/matrix
pnpm run ci-check
```

### Before

On main `cad9015` with the contracts as they were:

```
 ❯ packages/lexical-y/src/__tests__/unit/matrix/CatalogSoakFuzz.test.ts (24 tests | 24 failed)
 ❯ packages/lexical-y/src/__tests__/unit/matrix/C1Busy.test.ts (96 tests | 16 failed)
 ❯ packages/lexical-y/src/__tests__/unit/matrix/C1ReadEqualsFresh.test.ts (435 tests | 139 failed)
      Tests  179 failed | 1973 passed | 32 expected fail (2184)
```

### After

On main `cad9015`:

```
 Test Files  12 passed (12)
      Tests  2152 passed | 32 expected fail (2184)

$ pnpm run ci-check
Found 0 errors
```
@zurfyx

zurfyx commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

Merged to main through the merge queue as ad3ccaa; GitHub did not mark this PR merged, so closing it by hand.

@zurfyx zurfyx closed this Oct 30, 2026
etrepum pushed a commit to etrepum/lexical that referenced this pull request Oct 30, 2026
…right away when the document holds a block with a named slot (meta#9573)

This branch was successfully deployed

2 active deployments
Preview – lexical — 035f17e5 Deployed Oct 30, 2026 by vercel[bot]
Preview – lexical-playground — 035f17e5 Deployed Oct 30, 2026 by vercel[bot]
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