Optimize graph state management & performance for tab switching visibility
• Reset graph data without recreating instance • Fix search result caching on graph updates
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { FC, useCallback, useMemo } from 'react'
|
||||
import { FC, useCallback, useEffect, useMemo } from 'react'
|
||||
import {
|
||||
EdgeById,
|
||||
NodeById,
|
||||
@@ -28,6 +28,7 @@ function OptionComponent(item: OptionItem) {
|
||||
}
|
||||
|
||||
const messageId = '__message_item'
|
||||
// Reset this cache when graph changes to ensure fresh search results
|
||||
const lastGraph: any = {
|
||||
graph: null,
|
||||
searchEngine: null
|
||||
@@ -48,6 +49,15 @@ export const GraphSearchInput = ({
|
||||
const { t } = useTranslation()
|
||||
const graph = useGraphStore.use.sigmaGraph()
|
||||
|
||||
// Force reset the cache when graph changes
|
||||
useEffect(() => {
|
||||
if (graph) {
|
||||
// Reset cache to ensure fresh search results with new graph data
|
||||
lastGraph.graph = null;
|
||||
lastGraph.searchEngine = null;
|
||||
}
|
||||
}, [graph]);
|
||||
|
||||
const searchEngine = useMemo(() => {
|
||||
if (lastGraph.graph == graph) {
|
||||
return lastGraph.searchEngine
|
||||
|
Reference in New Issue
Block a user