Skip to content

Commit

Permalink
[lexical-playground] fix: Image component rerenders on every editor u…
Browse files Browse the repository at this point in the history
…pdate
  • Loading branch information
jvithlani committed Feb 22, 2025
1 parent 90bc029 commit ce35099
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/lexical-playground/src/nodes/ImageComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,14 @@ export default function ImageComponent({
);

useEffect(() => {
let isMounted = true;
const rootElement = editor.getRootElement();
const unregister = mergeRegister(
editor.registerUpdateListener(({editorState}) => {
if (isMounted) {
setSelection(editorState.read(() => $getSelection()));
const updatedSelection = editorState.read(() => $getSelection());
if ($isNodeSelection(updatedSelection)) {
setSelection(updatedSelection);
} else {
setSelection(null);
}
}),
editor.registerCommand(
Expand Down Expand Up @@ -345,7 +347,6 @@ export default function ImageComponent({
rootElement?.addEventListener('contextmenu', onRightClick);

return () => {
isMounted = false;
unregister();
rootElement?.removeEventListener('contextmenu', onRightClick);
};
Expand Down

0 comments on commit ce35099

Please sign in to comment.