A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.
fix(app): missing useCallback dependencie for layouting
dextmorgnb5df7fd62910
diff --git a/flowsint-app/src/components/sketches/graph-viewer.tsx b/flowsint-app/src/components/sketches/graph-viewer.tsxindex 53da0829..36fcc963 100644--- a/flowsint-app/src/components/sketches/graph-viewer.tsx+++ b/flowsint-app/src/components/sketches/graph-viewer.tsx@@ -263,16 +263,6 @@ const GraphViewer: React.FC<GraphViewerProps> = ({}}, [nodes, showIcons])- // const handleZoom = useCallback((zoom: any) => {- // const prevZoom = zoomRef.current.k- // zoomRef.current = zoom- // // Only update state if zoom changed significantly (reduces re-renders)- // const newZoom = zoom.k- // if (Math.abs(newZoom - prevZoom) > 0.1) {- // setCurrentZoom(newZoom)- // }- // }, [])-// Handle container size changesuseEffect(() => {const updateSize = () => {@@ -414,6 +404,8 @@ const GraphViewer: React.FC<GraphViewerProps> = ({try {await applyLayout({layoutType,+ nodes: graphData.nodes,+ edges: graphData.links})// Zoom to fit after layout is complete@@ -429,8 +421,8 @@ const GraphViewer: React.FC<GraphViewerProps> = ({console.error('Layout calculation failed:', error)setIsRegeneratingLayout(false)}- })- }, [applyLayout, setCurrentLayoutType])+ }, 100)+ }, [applyLayout, setCurrentLayoutType, graphData.nodes, graphData.links])// Optimized graph initialization callbackconst initializeGraph = useCallback(diff --git a/flowsint-app/src/hooks/use-layout.ts b/flowsint-app/src/hooks/use-layout.tsindex 201c8a06..f446152d 100644--- a/flowsint-app/src/hooks/use-layout.ts+++ b/flowsint-app/src/hooks/use-layout.ts@@ -1,6 +1,5 @@import { useCallback, useRef, useEffect } from 'react'-import { GraphNode } from '@/types'-import { useGraphStore } from '@/stores/graph-store';+import { GraphEdge, GraphNode } from '@/types'interface UseLayoutProps {forceSettings: any@@ -11,6 +10,8 @@ interface UseLayoutProps {interface LayoutOptions {layoutType: 'force' | 'hierarchy'+ nodes: GraphNode[],+ edges: GraphEdge[]}export function useLayout({@@ -20,9 +21,6 @@ export function useLayout({onProgress,}: UseLayoutProps) {const workerRef = useRef<Worker | null>(null)- const setNodes = useGraphStore(s => s.setNodes)- const nodes = useGraphStore(s => s.nodes)- const edges = useGraphStore(s => s.edges)// Initialize worker onceuseEffect(() => {@@ -37,7 +35,8 @@ export function useLayout({}, [])const applyLayout = useCallback(- async ({ layoutType }: LayoutOptions) => {+ async ({ nodes, edges, layoutType }: LayoutOptions) => {+ console.log(nodes)if (!workerRef.current) {throw new Error('Layout worker not initialized')}@@ -56,7 +55,6 @@ export function useLayout({onProgress?.(event.data.progress)} else if (event.data.type === 'complete') {const { nodes: layoutedNodes } = event.data.result-// // Apply the calculated positions to the graph nodeslayoutedNodes.forEach((layoutedNode: any) => {const graphNode = nodes.find((n: any) => n.id === layoutedNode.id) as any@@ -67,7 +65,6 @@ export function useLayout({graphNode.fy = layoutedNode.y}})- setNodes(layoutedNodes)// Save all node positionssaveAllNodePositions(nodes, true)