Remove redundant sigma instance setup code in GraphViewer component
• Remove unused useLayoutEffect hook
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -8,7 +8,7 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="./logo.png" />
|
<link rel="icon" type="image/svg+xml" href="./logo.png" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Lightrag</title>
|
<title>Lightrag</title>
|
||||||
<script type="module" crossorigin src="./assets/index-B11jRN0T.js"></script>
|
<script type="module" crossorigin src="./assets/index-B_8hp7Xk.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="./assets/index-TPDyec81.css">
|
<link rel="stylesheet" crossorigin href="./assets/index-TPDyec81.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@@ -75,7 +75,7 @@ const GraphControl = ({ disableHoverEffect }: { disableHoverEffect?: boolean })
|
|||||||
// Double-check that the store has the sigma instance
|
// Double-check that the store has the sigma instance
|
||||||
const currentInstance = useGraphStore.getState().sigmaInstance;
|
const currentInstance = useGraphStore.getState().sigmaInstance;
|
||||||
if (!currentInstance) {
|
if (!currentInstance) {
|
||||||
console.log('Setting sigma instance from GraphControl (backup)');
|
console.log('Setting sigma instance from GraphControl');
|
||||||
useGraphStore.getState().setSigmaInstance(sigma);
|
useGraphStore.getState().setSigmaInstance(sigma);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useLayoutEffect, useState, useCallback, useMemo, useRef } from 'react'
|
import { useEffect, useState, useCallback, useMemo, useRef } from 'react'
|
||||||
import { useTabVisibility } from '@/contexts/useTabVisibility'
|
import { useTabVisibility } from '@/contexts/useTabVisibility'
|
||||||
// import { MiniMap } from '@react-sigma/minimap'
|
// import { MiniMap } from '@react-sigma/minimap'
|
||||||
import { SigmaContainer, useRegisterEvents, useSigma } from '@react-sigma/core'
|
import { SigmaContainer, useRegisterEvents, useSigma } from '@react-sigma/core'
|
||||||
@@ -157,39 +157,9 @@ const GraphViewer = () => {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Get the sigmaGraph from the store
|
// Note: There was a useLayoutEffect hook here to set up the sigma instance and graph data,
|
||||||
const sigmaGraph = useGraphStore.use.sigmaGraph();
|
// but testing showed it wasn't executing or having any effect, while the backup mechanism
|
||||||
|
// in GraphControl was sufficient. This code was removed to simplify implementation
|
||||||
// Set the sigma instance in the graph store when it's available
|
|
||||||
// Using useLayoutEffect to ensure this runs before child components need the instance
|
|
||||||
useLayoutEffect(() => {
|
|
||||||
if (sigmaRef.current?.sigma) {
|
|
||||||
const instance = sigmaRef.current.sigma;
|
|
||||||
|
|
||||||
// Get the sigma instance from the ref and store it
|
|
||||||
console.log('Setting sigma instance in graph store (layout effect)');
|
|
||||||
useGraphStore.getState().setSigmaInstance(instance);
|
|
||||||
|
|
||||||
// If we also have a graph, bind it to the sigma instance
|
|
||||||
if (sigmaGraph) {
|
|
||||||
try {
|
|
||||||
// Try to set the graph on the sigma instance
|
|
||||||
if (typeof instance.setGraph === 'function') {
|
|
||||||
instance.setGraph(sigmaGraph);
|
|
||||||
console.log('Directly set graph on sigma instance in GraphViewer');
|
|
||||||
} else {
|
|
||||||
// If setGraph method doesn't exist, try to set the graph property directly
|
|
||||||
(instance as any).graph = sigmaGraph;
|
|
||||||
console.log('Set graph property on sigma instance in GraphViewer');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error setting graph on sigma instance in GraphViewer:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// We want this to run when either the ref or the graph changes
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, [sigmaRef.current, sigmaGraph]);
|
|
||||||
|
|
||||||
const onSearchFocus = useCallback((value: GraphSearchOption | null) => {
|
const onSearchFocus = useCallback((value: GraphSearchOption | null) => {
|
||||||
if (value === null) useGraphStore.getState().setFocusedNode(null)
|
if (value === null) useGraphStore.getState().setFocusedNode(null)
|
||||||
|
Reference in New Issue
Block a user