From dc74c889b0343627f4bb48c751d81970405bd1e3 Mon Sep 17 00:00:00 2001 From: yangdx Date: Thu, 13 Mar 2025 01:25:17 +0800 Subject: [PATCH] Clear selection and highlights before graph fetch - Reset node selection before fetching - Remove existing node highlights - Prevent react rendering broken problem --- lightrag_webui/src/hooks/useLightragGraph.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lightrag_webui/src/hooks/useLightragGraph.tsx b/lightrag_webui/src/hooks/useLightragGraph.tsx index a5e414b9..a8c43434 100644 --- a/lightrag_webui/src/hooks/useLightragGraph.tsx +++ b/lightrag_webui/src/hooks/useLightragGraph.tsx @@ -214,7 +214,16 @@ const useLightrangeGraph = () => { // Only fetch if we haven't fetched this combination in the current component lifecycle if (!isFetching && !fetchStatusRef.current[fetchKey]) { - useGraphStore.getState().setIsFetching(true); + const state = useGraphStore.getState(); + // Clear selection and highlighted nodes before fetching new graph + state.clearSelection(); + if (state.sigmaGraph) { + state.sigmaGraph.forEachNode((node) => { + state.sigmaGraph?.setNodeAttribute(node, 'highlighted', false); + }); + } + + state.setIsFetching(true); fetchStatusRef.current[fetchKey] = true; fetchGraph(queryLabel, maxQueryDepth, minDegree).then((data) => { const state = useGraphStore.getState()