Skip to content

Commit

Permalink
fix: Optimize frameToHighlight state change and snapLines state change (
Browse files Browse the repository at this point in the history
excalidraw#8763)

Fix case when frame interactions recursively call setState() without any change.
  • Loading branch information
mtolmacs authored Nov 21, 2024
1 parent d21e000 commit ab8b353
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/excalidraw/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7940,10 +7940,14 @@ class App extends React.Component<AppProps, AppState> {
isFrameLikeElement(e),
);
const topLayerFrame = this.getTopLayerFrameAtSceneCoords(pointerCoords);
this.setState({
frameToHighlight:
topLayerFrame && !selectedElementsHasAFrame ? topLayerFrame : null,
});
const frameToHighlight =
topLayerFrame && !selectedElementsHasAFrame ? topLayerFrame : null;
// Only update the state if there is a difference
if (this.state.frameToHighlight !== frameToHighlight) {
flushSync(() => {
this.setState({ frameToHighlight });
});
}

// Marking that click was used for dragging to check
// if elements should be deselected on pointerup
Expand Down Expand Up @@ -8090,7 +8094,9 @@ class App extends React.Component<AppProps, AppState> {
this.scene.getNonDeletedElementsMap(),
);

this.setState({ snapLines });
flushSync(() => {
this.setState({ snapLines });
});

// when we're editing the name of a frame, we want the user to be
// able to select and interact with the text input
Expand Down

0 comments on commit ab8b353

Please sign in to comment.