Skip to content

Commit

Permalink
Fix clear rootElement on React (facebook#6389)
Browse files Browse the repository at this point in the history
  • Loading branch information
zurfyx authored and 2wheeh committed Jul 17, 2024
1 parent 1d1f0fd commit 9bdaade
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export function ContentEditableElement({
rootElement.ownerDocument.defaultView
) {
editor.setRootElement(rootElement);
} else {
editor.setRootElement(null);
}
},
[editor],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import {$createLinkNode} from '@lexical/link';
import {$createListItemNode, $createListNode} from '@lexical/list';
import {AutoFocusPlugin} from '@lexical/react/LexicalAutoFocusPlugin';
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
import {ContentEditable} from '@lexical/react/LexicalContentEditable';
import {LexicalErrorBoundary} from '@lexical/react/LexicalErrorBoundary';
Expand Down Expand Up @@ -187,6 +188,7 @@ describe('LexicalSelection tests', () => {
/>
<HistoryPlugin />
<TestPlugin />
<AutoFocusPlugin />
</TestComposer>
);
}
Expand All @@ -195,7 +197,6 @@ describe('LexicalSelection tests', () => {
reactRoot.render(<TestBase />);
await Promise.resolve().then();
});
editor!.getRootElement()!.focus();

await Promise.resolve().then();
// Focus first element
Expand Down Expand Up @@ -2269,7 +2270,7 @@ describe('LexicalSelection tests', () => {
});

it('adjust offset for inline elements text formatting', async () => {
init();
await init();

await editor!.update(() => {
const root = $getRoot();
Expand Down
1 change: 0 additions & 1 deletion packages/lexical/src/LexicalEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,6 @@ export class LexicalEditor {
listener(this._rootElement, null);
listenerSetOrMap.add(listener);
return () => {
listener(null, this._rootElement);
listenerSetOrMap.delete(listener);
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ describe('LexicalEditor tests', () => {
[editor] = useLexicalComposerContext();

useEffect(() => {
editor.registerRootListener(listener);
return editor.registerRootListener(listener);
}, []);

return null;
Expand Down Expand Up @@ -1011,7 +1011,7 @@ describe('LexicalEditor tests', () => {
await Promise.resolve().then();
});

expect(listener).toHaveBeenCalledTimes(3);
expect(listener).toHaveBeenCalledTimes(4);
expect(container.innerHTML).toBe(
'<div contenteditable="true" style="user-select: text; white-space: pre-wrap; word-break: break-word;" data-lexical-editor="true"><p><br></p></div>',
);
Expand Down

0 comments on commit 9bdaade

Please sign in to comment.