Skip to content

A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.

feat(app): polling to check graph initialization

dextmorgnd6eedbfbc33c
diff --git a/flowsint-app/src/components/sketches/graph/use-graph-initialization.ts b/flowsint-app/src/components/sketches/graph/use-graph-initialization.ts
index fbee7f3c..7a93c136 100644
--- a/flowsint-app/src/components/sketches/graph/use-graph-initialization.ts
+++ b/flowsint-app/src/components/sketches/graph/use-graph-initialization.ts
@@ -20,7 +20,6 @@ export const useGraphInitialization = ({
const isGraphReadyRef = useRef(false)
const regenerateLayoutRef = useRef(regenerateLayout)
- // Keep ref updated
useEffect(() => {
regenerateLayoutRef.current = regenerateLayout
}, [regenerateLayout])
@@ -40,10 +39,8 @@ export const useGraphInitialization = ({
}, 100)
return
}
-
if (isGraphReadyRef.current) return
isGraphReadyRef.current = true
-
// Initial zoom to fit
setTimeout(() => {
if (graphRef.current && typeof graphRef.current.zoomToFit === 'function') {
@@ -106,12 +103,28 @@ export const useGraphInitialization = ({
[setActions, onGraphRef, instanceId, selectedNodeIdsRef, graphRef]
)
+ // Poll for graphRef to be ready
useEffect(() => {
- if (graphRef.current) {
- initializeGraph(graphRef.current)
+ const checkAndInitialize = () => {
+ if (graphRef.current && !isGraphReadyRef.current) {
+ initializeGraph(graphRef.current)
+ }
}
+ // Check immediately
+ checkAndInitialize()
+
+ // Then check every 100ms until initialized
+ const interval = setInterval(() => {
+ if (isGraphReadyRef.current) {
+ clearInterval(interval)
+ } else {
+ checkAndInitialize()
+ }
+ }, 100)
+
return () => {
+ clearInterval(interval)
if (!instanceId && isGraphReadyRef.current) {
setActions({
zoomIn: () => { },
diff --git a/flowsint-app/src/hooks/use-layout.ts b/flowsint-app/src/hooks/use-layout.ts
index f446152d..5621f75e 100644
--- a/flowsint-app/src/hooks/use-layout.ts
+++ b/flowsint-app/src/hooks/use-layout.ts
@@ -36,17 +36,14 @@ export function useLayout({
const applyLayout = useCallback(
async ({ nodes, edges, layoutType }: LayoutOptions) => {
- console.log(nodes)
if (!workerRef.current) {
throw new Error('Layout worker not initialized')
}
-
// Remove fx and fy from all nodes to allow repositioning
nodes.forEach((node: any) => {
delete node.fx
delete node.fy
})
-
return new Promise<GraphNode[]>((resolve, reject) => {
const worker = workerRef.current!