Skip to content

Commit

Permalink
Revert "[Breaking Change][lexical] Bug Fix: Commit updates on editor.…
Browse files Browse the repository at this point in the history
…setRootElement(null) (#7023)"

This reverts commit d7abafd.
  • Loading branch information
potatowagon committed Jan 15, 2025
1 parent 65ce66a commit 2bacd43
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
12 changes: 4 additions & 8 deletions packages/lexical/src/LexicalEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1101,15 +1101,11 @@ export class LexicalEditor {
}
}
} else {
// When the content editable is unmounted we will still trigger a
// reconciliation so that any pending updates are flushed,
// to match the previous state change when
// `_editorState = pendingEditorState` was used, but by
// using a commit we preserve the readOnly invariant
// for editor.getEditorState().
// If content editable is unmounted we'll reset editor state back to original
// (or pending) editor state since there will be no reconciliation
this._editorState = pendingEditorState;
this._pendingEditorState = null;
this._window = null;
this._updateTags.add('history-merge');
$commitPendingUpdates(this);
}

triggerListeners('root', this, false, nextRootElement, prevRootElement);
Expand Down
8 changes: 1 addition & 7 deletions packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ describe('LexicalEditor tests', () => {
});

expect(rootListener).toHaveBeenCalledTimes(3);
expect(updateListener).toHaveBeenCalledTimes(4);
expect(updateListener).toHaveBeenCalledTimes(3);
expect(container.innerHTML).toBe(
'<span contenteditable="true" style="user-select: text; white-space: pre-wrap; word-break: break-word;" data-lexical-editor="true"><p dir="ltr"><span data-lexical-text="true">Change successful</span></p></span>',
);
Expand All @@ -1032,13 +1032,7 @@ describe('LexicalEditor tests', () => {
init();
const contentEditable = editor.getRootElement();
editor.setEditable(editable);
editor.update(() => {
// Cause the editor to become dirty, so we can ensure
// that the getEditorState()._readOnly invariant holds
$getRoot().markDirty();
});
editor.setRootElement(null);
expect(editor.getEditorState()._readOnly).toBe(true);
const editorState = editor.parseEditorState(JSON_EDITOR_STATE);
editor.setEditorState(editorState);
editor.update(() => {
Expand Down

0 comments on commit 2bacd43

Please sign in to comment.