diff --git a/lightrag_webui/src/components/graph/GraphControl.tsx b/lightrag_webui/src/components/graph/GraphControl.tsx
index af7cf250..e4e0a96a 100644
--- a/lightrag_webui/src/components/graph/GraphControl.tsx
+++ b/lightrag_webui/src/components/graph/GraphControl.tsx
@@ -142,6 +142,15 @@ const GraphControl = ({ disableHoverEffect }: { disableHoverEffect?: boolean })
// Register the events
registerEvents(events)
+
+ // Cleanup function - basic cleanup without relying on specific APIs
+ return () => {
+ try {
+ console.log('Cleaning up graph event listeners')
+ } catch (error) {
+ console.warn('Error cleaning up graph event listeners:', error)
+ }
+ }
}, [registerEvents, enableEdgeEvents, sigma])
/**
@@ -189,6 +198,7 @@ const GraphControl = ({ disableHoverEffect }: { disableHoverEffect?: boolean })
}
}, [sigma, sigmaGraph, minEdgeSize, maxEdgeSize])
+
/**
* When component mount or hovered node change
* => Setting the sigma reducers
@@ -208,6 +218,13 @@ const GraphControl = ({ disableHoverEffect }: { disableHoverEffect?: boolean })
// Node reducer for node appearance
nodeReducer: (node, data) => {
const graph = sigma.getGraph()
+
+ // Add defensive check for node existence during theme switching
+ if (!graph.hasNode(node)) {
+ console.warn(`Node ${node} not found in graph during theme switch, returning default data`)
+ return { ...data, highlighted: false, labelColor }
+ }
+
const newData: NodeType & {
labelColor?: string
borderColor?: string
@@ -228,11 +245,17 @@ const GraphControl = ({ disableHoverEffect }: { disableHoverEffect?: boolean })
}
} catch (error) {
console.error('Error in nodeReducer:', error);
+ return { ...data, highlighted: false, labelColor }
}
} else if (_focusedEdge && graph.hasEdge(_focusedEdge)) {
- if (graph.extremities(_focusedEdge).includes(node)) {
- newData.highlighted = true
- newData.size = 3
+ try {
+ if (graph.extremities(_focusedEdge).includes(node)) {
+ newData.highlighted = true
+ newData.size = 3
+ }
+ } catch (error) {
+ console.error('Error accessing edge extremities in nodeReducer:', error);
+ return { ...data, highlighted: false, labelColor }
}
} else {
return newData
@@ -252,6 +275,13 @@ const GraphControl = ({ disableHoverEffect }: { disableHoverEffect?: boolean })
// Edge reducer for edge appearance
edgeReducer: (edge, data) => {
const graph = sigma.getGraph()
+
+ // Add defensive check for edge existence during theme switching
+ if (!graph.hasEdge(edge)) {
+ console.warn(`Edge ${edge} not found in graph during theme switch, returning default data`)
+ return { ...data, hidden: false, labelColor, color: edgeColor }
+ }
+
const newData = { ...data, hidden: false, labelColor, color: edgeColor }
if (!disableHoverEffect) {
@@ -270,6 +300,7 @@ const GraphControl = ({ disableHoverEffect }: { disableHoverEffect?: boolean })
}
} catch (error) {
console.error('Error in edgeReducer:', error);
+ return { ...data, hidden: false, labelColor, color: edgeColor }
}
} else {
const _selectedEdge = selectedEdge && graph.hasEdge(selectedEdge) ? selectedEdge : null;
diff --git a/lightrag_webui/src/components/graph/GraphSearch.tsx b/lightrag_webui/src/components/graph/GraphSearch.tsx
index 40840f59..d181c6b3 100644
--- a/lightrag_webui/src/components/graph/GraphSearch.tsx
+++ b/lightrag_webui/src/components/graph/GraphSearch.tsx
@@ -1,7 +1,6 @@
import { FC, useCallback, useEffect } from 'react'
import {
EdgeById,
- NodeById,
GraphSearchInputProps,
GraphSearchContextProviderProps
} from '@react-sigma/graph-search'
@@ -23,10 +22,31 @@ export interface OptionItem {
const NodeOption = ({ id }: { id: string }) => {
const graph = useGraphStore.use.sigmaGraph()
+
+ // Early return if no graph or node doesn't exist
if (!graph?.hasNode(id)) {
return null
}
- return
Loading Graph Data...
+{isThemeSwitching ? 'Switching Theme...' : 'Loading Graph Data...'}