Fix: Use ref to track graph loading state instead of checking graphNodes.length in useEffect
Browse files- frontend/src/App.tsx +9 -2
frontend/src/App.tsx
CHANGED
|
@@ -104,6 +104,9 @@ function App() {
|
|
| 104 |
// Threshold for using instanced rendering
|
| 105 |
const INSTANCED_THRESHOLD = 10000;
|
| 106 |
|
|
|
|
|
|
|
|
|
|
| 107 |
const [, setSearchResults] = useState<SearchResult[]>([]);
|
| 108 |
const [searchInput] = useState('');
|
| 109 |
const [, setShowSearchResults] = useState(false);
|
|
@@ -458,8 +461,11 @@ function App() {
|
|
| 458 |
|
| 459 |
// Load force graph data when vizMode is 'force-graph'
|
| 460 |
useEffect(() => {
|
| 461 |
-
if (vizMode !== 'force-graph')
|
| 462 |
-
|
|
|
|
|
|
|
|
|
|
| 463 |
|
| 464 |
const loadForceGraph = async () => {
|
| 465 |
setGraphLoading(true);
|
|
@@ -479,6 +485,7 @@ function App() {
|
|
| 479 |
setEnabledEdgeTypes(availableTypes);
|
| 480 |
}
|
| 481 |
}
|
|
|
|
| 482 |
} catch (err) {
|
| 483 |
setGraphError(err instanceof Error ? err.message : 'Failed to load graph');
|
| 484 |
} finally {
|
|
|
|
| 104 |
// Threshold for using instanced rendering
|
| 105 |
const INSTANCED_THRESHOLD = 10000;
|
| 106 |
|
| 107 |
+
// Track if force graph has been loaded
|
| 108 |
+
const graphLoadedRef = useRef(false);
|
| 109 |
+
|
| 110 |
const [, setSearchResults] = useState<SearchResult[]>([]);
|
| 111 |
const [searchInput] = useState('');
|
| 112 |
const [, setShowSearchResults] = useState(false);
|
|
|
|
| 461 |
|
| 462 |
// Load force graph data when vizMode is 'force-graph'
|
| 463 |
useEffect(() => {
|
| 464 |
+
if (vizMode !== 'force-graph') {
|
| 465 |
+
graphLoadedRef.current = false;
|
| 466 |
+
return;
|
| 467 |
+
}
|
| 468 |
+
if (graphLoadedRef.current) return; // Already loaded
|
| 469 |
|
| 470 |
const loadForceGraph = async () => {
|
| 471 |
setGraphLoading(true);
|
|
|
|
| 485 |
setEnabledEdgeTypes(availableTypes);
|
| 486 |
}
|
| 487 |
}
|
| 488 |
+
graphLoadedRef.current = true;
|
| 489 |
} catch (err) {
|
| 490 |
setGraphError(err instanceof Error ? err.message : 'Failed to load graph');
|
| 491 |
} finally {
|