Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.

Commit 44b0bbe

Browse files
authored
Merge pull request #2922 from withspectrum/fix-toolbar-infinite-loop
Fix infinite loop in rich text editor
2 parents c36ef34 + d1f1013 commit 44b0bbe

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/components/rich-text-editor/toolbar.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,19 @@ export default class Toolbar extends React.Component<Props, State> {
6868
return;
6969
}
7070
if (!editor || typeof editor.getBoundingClientRect !== 'function') return;
71+
const topPosition = top + scrollY;
72+
const leftPosition = editor.getBoundingClientRect().left - 48;
73+
// If the position hasn't changed, don't re-render
74+
if (
75+
this.state.position &&
76+
topPosition === this.state.position.top &&
77+
leftPosition === this.state.position.left
78+
)
79+
return;
7180
this.setState({
7281
position: {
73-
top: top + scrollY,
74-
left: editor.getBoundingClientRect().left - 48,
82+
top: topPosition,
83+
left: leftPosition,
7584
},
7685
});
7786
}, 0);

0 commit comments

Comments
 (0)