Repository navigation
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
lexical
@lexical/a11y
@lexical/clipboard
@lexical/code
@lexical/code-core
@lexical/code-prism
@lexical/code-shiki
@lexical/compiler
@lexical/devtools-core
@lexical/dragon
@lexical/eslint-plugin
@lexical/extension
@lexical/fast-check
@lexical/file
@lexical/hashtag
@lexical/headless
@lexical/history
@lexical/html
@lexical/internal
@lexical/link
@lexical/list
@lexical/mark
@lexical/markdown
@lexical/mdast
@lexical/offset
@lexical/overflow
@lexical/plain-text
@lexical/react
@lexical/rich-text
@lexical/selection
@lexical/table
@lexical/tailwind
@lexical/text
@lexical/utils
@lexical/y
@lexical/yjs
commit: |
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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.
…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 ```
|
Merged to main through the merge queue as ad3ccaa; GitHub did not mark this PR merged, so closing it by hand. |
…right away when the document holds a block with a named slot (meta#9573)
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 customstartwas ignored. A freshreadYStateof 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(andindent) 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.setEditablere-renders in an update of its own ($fullReconcile). That update was still pending when the read'safter()calledflushRefresh. The editor was therefore not idle, and the refresh waited forrunPendinga 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)).flushRefreshnow 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 pastMAX_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:YBindingstart and initialize on a mounted editor,YCollabExtensionwithsynced, andYCollabExtensioninitialized after mount.getValue(),<li value>and the list starts;readYState.readYState.The
YCollabExtensioncases 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
After
@lexical/yunit suite: 166 files pass (7502 passed, 46 expected fail, 4 skipped).lexicalunit suite: 102 files, 2390 passed.Fuzz.test.tsseeds 1..3000 and gc seeds 1..600, plusSlotsFuzz,ConcurrentShapesFuzz,FollowUpFuzz,NestedFuzz,FuzzReplay,BlockIdFuzzSeedsat their defaults): same as main (seed 2277 only, a documented limit).pnpm run ci-checkpasses.