From 61734313b25d99cb8eef41a7530af3a71235b9be Mon Sep 17 00:00:00 2001 From: yangdx Date: Wed, 19 Mar 2025 13:51:15 +0800 Subject: [PATCH] Remove useless tab visibility checks from graph components --- lightrag_webui/src/features/GraphViewer.tsx | 15 +----------- lightrag_webui/src/hooks/useLightragGraph.tsx | 23 ++----------------- 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/lightrag_webui/src/features/GraphViewer.tsx b/lightrag_webui/src/features/GraphViewer.tsx index ee55228f..cf46debc 100644 --- a/lightrag_webui/src/features/GraphViewer.tsx +++ b/lightrag_webui/src/features/GraphViewer.tsx @@ -1,5 +1,4 @@ import { useEffect, useState, useCallback, useMemo, useRef } from 'react' -import { useTabVisibility } from '@/contexts/useTabVisibility' // import { MiniMap } from '@react-sigma/minimap' import { SigmaContainer, useRegisterEvents, useSigma } from '@react-sigma/core' import { Settings as SigmaSettings } from 'sigma/settings' @@ -114,27 +113,15 @@ const GraphViewer = () => { const moveToSelectedNode = useGraphStore.use.moveToSelectedNode() const isFetching = useGraphStore.use.isFetching() - // Get tab visibility - const { isTabVisible } = useTabVisibility() - const isGraphTabVisible = isTabVisible('knowledge-graph') - const showPropertyPanel = useSettingsStore.use.showPropertyPanel() const showNodeSearchBar = useSettingsStore.use.showNodeSearchBar() const enableNodeDrag = useSettingsStore.use.enableNodeDrag() - // Handle component mount/unmount and tab visibility - useEffect(() => { - return () => { - // Only log, keep everything untouched - // This allows the WebGL context to persist across tab switches - console.log('GraphViewer is invisible, WebGL context is persisting') - } - }, [isGraphTabVisible]) - // Initialize sigma settings once on component mount // All dynamic settings will be updated in GraphControl using useSetSettings useEffect(() => { setSigmaSettings(defaultSigmaSettings) + console.log('Initialized sigma settings') }, []) // Clean up sigma instance when component unmounts diff --git a/lightrag_webui/src/hooks/useLightragGraph.tsx b/lightrag_webui/src/hooks/useLightragGraph.tsx index 5f51c234..0a847828 100644 --- a/lightrag_webui/src/hooks/useLightragGraph.tsx +++ b/lightrag_webui/src/hooks/useLightragGraph.tsx @@ -8,7 +8,6 @@ import { toast } from 'sonner' import { queryGraphs } from '@/api/lightrag' import { useBackendState } from '@/stores/state' import { useSettingsStore } from '@/stores/settings' -import { useTabVisibility } from '@/contexts/useTabVisibility' import seedrandom from 'seedrandom' @@ -189,11 +188,7 @@ const useLightrangeGraph = () => { const isFetching = useGraphStore.use.isFetching() const nodeToExpand = useGraphStore.use.nodeToExpand() const nodeToPrune = useGraphStore.use.nodeToPrune() - - // Get tab visibility - const { isTabVisible } = useTabVisibility() - const isGraphTabVisible = isTabVisible('knowledge-graph') - + // Track previous parameters to detect actual changes const prevParamsRef = useRef({ queryLabel, maxQueryDepth, minDegree }) @@ -248,12 +243,6 @@ const useLightrangeGraph = () => { if (!isFetching && !fetchInProgressRef.current && (paramsChanged || !useGraphStore.getState().graphDataFetchAttempted)) { - // Only fetch data if the Graph tab is visible and we haven't attempted a fetch yet - if (!isGraphTabVisible) { - console.log('Graph tab not visible, skipping data fetch'); - return; - } - // Set flags fetchInProgressRef.current = true useGraphStore.getState().setGraphDataFetchAttempted(true) @@ -316,15 +305,7 @@ const useLightrangeGraph = () => { state.setGraphDataFetchAttempted(false) }) } - }, [queryLabel, maxQueryDepth, minDegree, isFetching, paramsChanged, isGraphTabVisible, rawGraph, sigmaGraph]) - - // Update rendering state and handle tab visibility changes - useEffect(() => { - // When tab becomes visible - if (isGraphTabVisible) { - // We no longer reset the fetch attempted flag here to prevent continuous API calls - } - }, [isGraphTabVisible, rawGraph]) + }, [queryLabel, maxQueryDepth, minDegree, isFetching, paramsChanged, rawGraph, sigmaGraph]) // Handle node expansion useEffect(() => {