From 1d3bbac1650ec1f8b32d6b625ae716567248470d Mon Sep 17 00:00:00 2001 From: martinRenou Date: Mon, 23 Jan 2023 13:42:33 +0100 Subject: [PATCH] Improve performance --- src/panelview/objecttree.tsx | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/panelview/objecttree.tsx b/src/panelview/objecttree.tsx index de2b0078..f955382b 100644 --- a/src/panelview/objecttree.tsx +++ b/src/panelview/objecttree.tsx @@ -208,30 +208,35 @@ class ObjectTreeReact extends React.Component { clients: Map ): void => { const localState = this.props.cpModel.jcadModel?.localState; + if (!localState) { return; } - let selectedNode: string | null = null; + const { selectedNode } = this.state; + + let newSelectedNode: string | null = null; if (localState.remoteUser) { // We are in following mode. // Sync selections from a remote user const remoteState = clients.get(localState.remoteUser); if (remoteState?.selected?.value) { - selectedNode = remoteState?.selected?.value; + newSelectedNode = remoteState?.selected?.value; } } else if (localState.selected.value) { - selectedNode = localState.selected.value; + newSelectedNode = localState.selected.value; } - const openNodes = [...this.state.openNodes]; + if (selectedNode !== newSelectedNode) { + const openNodes = [...this.state.openNodes]; - if (selectedNode && openNodes.indexOf(selectedNode) === -1) { - openNodes.push(selectedNode); - } + if (newSelectedNode && openNodes.indexOf(newSelectedNode) === -1) { + openNodes.push(newSelectedNode); + } - this.setState(old => ({ ...old, openNodes, selectedNode })); + this.setState(old => ({ ...old, openNodes, selectedNode })); + } }; private _onClientSharedOptionsChanged = (