Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
perf(canvas): per-id slice subscriptions for node status broadcasts
trohitgf3455fb0790a
diff --git a/client/src/components/GenericNode.tsx b/client/src/components/GenericNode.tsxindex 3e5c470a..787d133e 100644--- a/client/src/components/GenericNode.tsx+++ b/client/src/components/GenericNode.tsx@@ -8,17 +8,17 @@ import { NodeData } from '../types/NodeTypes';import { INodeInputDefinition, INodeOutputDefinition, NodeConnectionType } from '../types/INodeProperties';import { useAppStore } from '../store/useAppStore';import { useAppTheme } from '../hooks/useAppTheme';-import { useWebSocket } from '../contexts/WebSocketContext';+import { useNodeStatus } from '../contexts/WebSocketContext';import EditableNodeLabel from './ui/EditableNodeLabel';const GenericNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectable, selected }) => {const theme = useAppTheme();const { setSelectedNode, setRenamingNodeId, updateNodeData } = useAppStore();- const { getNodeStatus } = useWebSocket();const isDisabled = data?.disabled === true;- // Get execution status from WebSocket- const nodeStatus = getNodeStatus(id);+ // Per-id slice subscription so an unrelated node's status update+ // does not re-render this generic node.+ const nodeStatus = useNodeStatus(id);const executionStatus = nodeStatus?.status || 'idle';const isExecuting = executionStatus === 'executing' || executionStatus === 'waiting';@@ -30,8 +30,8 @@ const GenericNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectaconst defaultLabel = definition?.displayName || type || '';const handleLabelChange = useCallback(- (newLabel: string) => updateNodeData(id, { ...data, label: newLabel }),- [id, data, updateNodeData]+ (newLabel: string) => updateNodeData(id, { label: newLabel }),+ [id, updateNodeData]);const handleLabelActivate = useCallback(() => setRenamingNodeId(id),diff --git a/client/src/components/SquareNode.tsx b/client/src/components/SquareNode.tsxindex dc68436e..c2e1b801 100644--- a/client/src/components/SquareNode.tsx+++ b/client/src/components/SquareNode.tsx@@ -5,7 +5,7 @@ import { NodeData } from '../types/NodeTypes';import { useAppStore } from '../store/useAppStore';import { useAppTheme } from '../hooks/useAppTheme';import EditableNodeLabel from './ui/EditableNodeLabel';-import { useWebSocket, useWhatsAppStatus } from '../contexts/WebSocketContext';+import { useWebSocket, useWhatsAppStatus, useNodeStatus } from '../contexts/WebSocketContext';import { getCachedNodeSpec, isNodeInBackendGroup, resolveNodeDescription, useNodeSpec } from '../lib/nodeSpec';import { resolveIcon, resolveLibraryIcon } from '../assets/icons';import { AI_MODEL_PROVIDER_MAP } from '../lib/aiModelProviders';@@ -34,9 +34,13 @@ const SquareNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectabconst { setSelectedNode, setRenamingNodeId, updateNodeData } = useAppStore();const isDisabled = data?.disabled === true;- // Get Android status, node status, and API key status from WebSocket context- const { androidStatus, getNodeStatus, getApiKeyStatus } = useWebSocket();- const nodeStatus = getNodeStatus(id);+ // Get Android status + API key status from the broad WebSocket+ // context, but subscribe to node status via the per-id slice selector+ // so an unrelated node's status update does NOT re-render this node.+ // Reference: zustand slice subscription pattern, see+ // https://github.com/pmndrs/zustand#selecting-multiple-state-slices+ const { androidStatus, getApiKeyStatus } = useWebSocket();+ const nodeStatus = useNodeStatus(id);const executionStatus = nodeStatus?.status || 'idle';// Minimum glow duration state - keeps glow visible for at least 500ms@@ -112,9 +116,13 @@ const SquareNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectabconst defaultLabel = definition?.displayName || type || '';+ // useAppStore.updateNodeData performs `{ ...node.data, ...newData }`+ // so we only need to pass the changed field. Dropping `data` from deps+ // keeps the callback ref stable across parent re-renders, which lets+ // the React.memo wrapper actually short-circuit.const handleLabelChange = useCallback(- (newLabel: string) => updateNodeData(id, { ...data, label: newLabel }),- [id, data, updateNodeData]+ (newLabel: string) => updateNodeData(id, { label: newLabel }),+ [id, updateNodeData]);const handleLabelActivate = useCallback(() => setRenamingNodeId(id),diff --git a/client/src/components/StartNode.tsx b/client/src/components/StartNode.tsxindex e57067ee..d33f0848 100644--- a/client/src/components/StartNode.tsx+++ b/client/src/components/StartNode.tsx@@ -14,8 +14,8 @@ const StartNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectablconst defaultLabel = 'Start';const handleLabelChange = useCallback(- (newLabel: string) => updateNodeData(id, { ...data, label: newLabel }),- [id, data, updateNodeData]+ (newLabel: string) => updateNodeData(id, { label: newLabel }),+ [id, updateNodeData]);const handleLabelActivate = useCallback(diff --git a/client/src/components/TriggerNode.tsx b/client/src/components/TriggerNode.tsxindex 80a8cb32..ae1fc757 100644--- a/client/src/components/TriggerNode.tsx+++ b/client/src/components/TriggerNode.tsx@@ -14,7 +14,7 @@ import { useAppStore } from '../store/useAppStore';import { resolveNodeDescription, useNodeSpec } from '../lib/nodeSpec';import { resolveIcon, resolveLibraryIcon } from '../assets/icons';import { useAppTheme } from '../hooks/useAppTheme';-import { useWebSocket, useWhatsAppStatus } from '../contexts/WebSocketContext';+import { useWhatsAppStatus, useNodeStatus } from '../contexts/WebSocketContext';import EditableNodeLabel from './ui/EditableNodeLabel';const TriggerNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectable, selected }) => {@@ -23,9 +23,9 @@ const TriggerNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectaconst [isConfigured, setIsConfigured] = useState(false);const isDisabled = data?.disabled === true;- // Get node status from WebSocket context- const { getNodeStatus } = useWebSocket();- const nodeStatus = getNodeStatus(id);+ // Per-id slice subscription so unrelated node-status broadcasts do+ // not re-render this trigger.+ const nodeStatus = useNodeStatus(id);const executionStatus = nodeStatus?.status || 'idle';// Check if this is a WhatsApp trigger@@ -48,9 +48,12 @@ const TriggerNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnecta}, [data]);const defaultLabel = definition?.displayName || type || '';+ // updateNodeData already merges partial updates onto existing node.data,+ // so passing only { label } avoids depending on the full data object+ // (which gets a fresh ref every parent render).const handleLabelChange = useCallback(- (newLabel: string) => updateNodeData(id, { ...data, label: newLabel }),- [id, data, updateNodeData]+ (newLabel: string) => updateNodeData(id, { label: newLabel }),+ [id, updateNodeData]);const handleLabelActivate = useCallback(() => setRenamingNodeId(id),