Skip to content

Commit

Permalink
Confirm useLexicalComposerContext behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
etrepum committed May 11, 2024
1 parent 65a7ea9 commit 1258399
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 55 deletions.
70 changes: 18 additions & 52 deletions examples/react-rich-collab/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/react-rich-collab/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@lexical/react-rich-example",
"name": "@lexical/react-rich-collab-example",
"private": true,
"version": "0.14.5",
"type": "module",
Expand Down
14 changes: 12 additions & 2 deletions packages/lexical-react/src/__tests__/unit/LexicalComposer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ describe('LexicalComposer tests', () => {
).forEach(({name, size}) => {
const Wrapper = React[name];
const editors = new Set<LexicalEditor>();
const pluginEditors = new Set<LexicalEditor>();
function Plugin() {
pluginEditors.add(useLexicalComposerContext()[0]);
return null;
}
function App() {
return (
<LexicalComposer
Expand All @@ -92,8 +97,9 @@ describe('LexicalComposer tests', () => {
onError: () => {
throw Error();
},
}}
/>
}}>
<Plugin />
</LexicalComposer>
);
}
it(`renders ${size} editors under ${name}`, async () => {
Expand All @@ -104,6 +110,8 @@ describe('LexicalComposer tests', () => {
</Wrapper>,
);
});
// 2 editors may be created since useMemo is still called twice,
// but only one result is used!
expect(editors.size).toBe(size);
[...editors].forEach((editor, i) => {
// This confirms that editorState() was only called once per editor,
Expand All @@ -113,6 +121,8 @@ describe('LexicalComposer tests', () => {
editor.getEditorState().read(() => $getRoot().getTextContent()),
]).toEqual([i, 'initial state']);
});
// Only one context is created in both cases though!
expect(pluginEditors.size).toBe(1);
});
});
});
Expand Down

0 comments on commit 1258399

Please sign in to comment.