yangdx commited on
Commit
e49e07c
·
1 Parent(s): d3a437a

fix: improve tab switching behavior to preserve WebGL context in graph viewer

Browse files

• Force mount inactive tabs
• Maintain WebGL context across tab switches
• Add visibility styles to TabsContent
• Update conditional rendering logic

lightrag_webui/src/components/ui/Tabs.tsx CHANGED
@@ -42,11 +42,13 @@ const TabsContent = React.forwardRef<
42
  <TabsPrimitive.Content
43
  ref={ref}
44
  className={cn(
45
- 'ring-offset-background focus-visible:ring-ring mt-2 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none',
 
 
46
  className
47
  )}
48
- // We no longer force mounting of inactive tabs
49
- // This prevents the Graph component from being mounted when it's not the active tab
50
  {...props}
51
  />
52
  ))
 
42
  <TabsPrimitive.Content
43
  ref={ref}
44
  className={cn(
45
+ 'ring-offset-background focus-visible:ring-ring focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none',
46
+ 'data-[state=inactive]:invisible data-[state=active]:visible',
47
+ 'h-full w-full',
48
  className
49
  )}
50
+ // Force mounting of inactive tabs to preserve WebGL contexts
51
+ forceMount
52
  {...props}
53
  />
54
  ))
lightrag_webui/src/features/GraphViewer.tsx CHANGED
@@ -140,8 +140,8 @@ const GraphViewer = () => {
140
 
141
  // Cleanup function when component unmounts
142
  return () => {
143
- // If we're navigating away from the graph tab completely (not just switching tabs)
144
- // we would clean up here, but for now we want to preserve the WebGL context
145
  console.log('Graph viewer cleanup')
146
  }
147
  }, [isGraphTabVisible, shouldRender, isFetching])
@@ -174,11 +174,12 @@ const GraphViewer = () => {
174
  [selectedNode]
175
  )
176
 
177
- // Only render the SigmaContainer when the tab is visible
 
178
  return (
179
  <div className="relative h-full w-full">
 
180
  {isGraphTabVisible ? (
181
- // Only render SigmaContainer when tab is visible
182
  <SigmaContainer
183
  settings={sigmaSettings}
184
  className="!bg-background !size-full overflow-hidden"
 
140
 
141
  // Cleanup function when component unmounts
142
  return () => {
143
+ // Only log cleanup, don't actually clean up the WebGL context
144
+ // This allows the WebGL context to persist across tab switches
145
  console.log('Graph viewer cleanup')
146
  }
147
  }, [isGraphTabVisible, shouldRender, isFetching])
 
174
  [selectedNode]
175
  )
176
 
177
+ // Since TabsContent now forces mounting of all tabs, we need to conditionally render
178
+ // the SigmaContainer based on visibility to avoid unnecessary rendering
179
  return (
180
  <div className="relative h-full w-full">
181
+ {/* Only render the SigmaContainer when the tab is visible */}
182
  {isGraphTabVisible ? (
 
183
  <SigmaContainer
184
  settings={sigmaSettings}
185
  className="!bg-background !size-full overflow-hidden"