Repository navigation
Conversation
|
@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. |
|
Confirmed the bug on main (two of the four new tests fail) and all four pass on this branch. The core fix — keying off |
| * pending would miss the parsed state entirely (and could stamp the flag onto | ||
| * an unrelated pending state). | ||
| */ | ||
| export function $markSlotsUsed(): void { |
There was a problem hiding this comment.
$markSlotsUsed was inserted between $removeFromParent's JSDoc (lines 488–500) and its function declaration (line 519). TSDoc binds only the immediately preceding block to the next declaration, so $removeFromParent ends up with no documentation. Move $markSlotsUsed (with its own JSDoc) to after $removeFromParent's closing brace.
| ); | ||
| } | ||
|
|
||
| function seedSlotDocument(editor: ReturnType<typeof buildEditor>) { |
There was a problem hiding this comment.
IosEnterAcceptanceBoundary.test.ts and LexicalDOMCapturedSelection.test.ts (unit-test peers in this package) annotate helper parameters as LexicalEditorWithDispose — the concrete return type of buildEditorFromExtensions. Consider import type {LexicalEditorWithDispose} from '@lexical/extension' and changing the parameter type accordingly.
## Description
`$setSlot` latches "this document uses slots" so the slot-gated paths know to
run. It marks the pending editor state:
```js
function $setSlotsUsed() {
const editor = $getEditor();
editor._slotsUsed = true;
if (editor._pendingEditorState) {
editor._pendingEditorState._slotsUsed = true;
}
}
```
Inside `editor.update()` that is correct, because `activeEditorState ===
editor._pendingEditorState`. But `$setSlot` also runs during
`parseEditorState` (`$parseSerializedNodeImpl`), and that function builds a
*detached* `EditorState` and assigns it to `activeEditorState` while leaving
`editor._pendingEditorState` untouched:
```js
const editorState = createEmptyEditorState();
...
activeEditorState = editorState; // _pendingEditorState is never touched
```
So a parsed state never receives the flag, and whatever unrelated state happens
to be pending may receive it instead.
`EditorState._slotsUsed` documents itself as "True if this EditorState or the
LexicalEditor that created it has ever used slots", and
`LexicalEditor.setEditorState` is the only way an editor learns that an
incoming state uses slots:
```js
this._slotsUsed = this._slotsUsed || editorState._slotsUsed;
```
An editor that receives a parsed slot document therefore keeps
`_slotsUsed === false` and silently skips every gated path —
`$clampRangeSelectionToSlotFrame` (so a RangeSelection may straddle a slot
boundary), the slot-island re-render in `setEditable`, and the slot walks in
`LexicalSelection`, `LexicalUtils` and `LexicalMutations`. `cloneEditorState`
and `EditorState.clone` both propagate the wrong `false` onward.
This marks the *active* editor state, which is the one actually being built in
both cases. The existing test `setEditorState latches _slotsUsed when the state
contains slots` covers the `update()` path, where the two are the same object;
the parse path was the gap.
The helper moves to `LexicalUtils` because `LexicalSlot` cannot import
`LexicalUpdates` directly — that edge forms a module-initialization cycle
(`LexicalSlot -> LexicalUpdates -> LexicalSelection -> LexicalTabNode ->
LexicalTextNode -> LexicalNode` still undefined), which is the same reason this
file already avoids a runtime `LexicalNode` import. `LexicalUtils` already
imports `getActiveEditorState` and is already imported by `LexicalSlot`.
## Test plan
New unit test `packages/lexical/src/__tests__/unit/SlotParseEditorState.test.ts`.
The third case has one editor parse and a *different* editor receive the state:
the parsing editor sets its own `_slotsUsed` as a side effect of `$setSlot`, so
only a receiving editor shows whether the flag travelled with the state. The
`update()` case and a slotless document are controls and pass before and after.
### Before
```
$ npx vitest run packages/lexical/src/__tests__/unit/SlotParseEditorState.test.ts
× a parsed state carries the flag 4ms
× setEditorState latches the flag on an editor that did not parse it 1ms
AssertionError: expected false to be true // Object.is equality
Tests 2 failed | 2 passed (4)
```
### After
```
$ npx vitest run packages/lexical/src/__tests__/unit/SlotParseEditorState.test.ts
Tests 4 passed (4)
$ npx vitest run packages/lexical/src/__tests__
Test Files 58 passed (58)
Tests 943 passed | 1 skipped (944)
```
faab6bb to
6017620
Compare
|
Both addressed in 6017620 — thanks for the careful read. The JSDoc one was a real defect I introduced: inserting Also switched the helper to 4/4 tests still pass. |
Description
$setSlotlatches "this document uses slots" so the slot-gated paths know torun. It marks the pending editor state:
Inside
editor.update()that is correct, becauseactiveEditorState === editor._pendingEditorState. But$setSlotalso runs duringparseEditorState($parseSerializedNodeImpl), and that function builds adetached
EditorStateand assigns it toactiveEditorStatewhile leavingeditor._pendingEditorStateuntouched:So a parsed state never receives the flag, and whatever unrelated state happens
to be pending may receive it instead.
EditorState._slotsUseddocuments itself as "True if this EditorState or theLexicalEditor that created it has ever used slots", and
LexicalEditor.setEditorStateis the only way an editor learns that anincoming state uses slots:
An editor that receives a parsed slot document therefore keeps
_slotsUsed === falseand silently skips every gated path —$clampRangeSelectionToSlotFrame(so a RangeSelection may straddle a slotboundary), the slot-island re-render in
setEditable, and the slot walks inLexicalSelection,LexicalUtilsandLexicalMutations.cloneEditorStateand
EditorState.cloneboth propagate the wrongfalseonward.This marks the active editor state, which is the one actually being built in
both cases. The existing test
setEditorState latches _slotsUsed when the state contains slotscovers theupdate()path, where the two are the same object;the parse path was the gap.
The helper moves to
LexicalUtilsbecauseLexicalSlotcannot importLexicalUpdatesdirectly — that edge forms a module-initialization cycle(
LexicalSlot -> LexicalUpdates -> LexicalSelection -> LexicalTabNode -> LexicalTextNode -> LexicalNodestill undefined), which is the same reason thisfile already avoids a runtime
LexicalNodeimport.LexicalUtilsalreadyimports
getActiveEditorStateand is already imported byLexicalSlot.Test plan
New unit test
packages/lexical/src/__tests__/unit/SlotParseEditorState.test.ts.The third case has one editor parse and a different editor receive the state:
the parsing editor sets its own
_slotsUsedas a side effect of$setSlot, soonly a receiving editor shows whether the flag travelled with the state. The
update()case and a slotless document are controls and pass before and after.Before
After