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

• Force mount inactive tabs
• Maintain WebGL context across tab switches
• Add visibility styles to TabsContent
• Update conditional rendering logic
This commit is contained in:
yangdx
2025-03-13 22:03:54 +08:00
parent b4d3da3b39
commit 1864da4f45
2 changed files with 10 additions and 7 deletions

View File

@@ -42,11 +42,13 @@ const TabsContent = React.forwardRef<
<TabsPrimitive.Content <TabsPrimitive.Content
ref={ref} ref={ref}
className={cn( className={cn(
'ring-offset-background focus-visible:ring-ring mt-2 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none', 'ring-offset-background focus-visible:ring-ring focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none',
'data-[state=inactive]:invisible data-[state=active]:visible',
'h-full w-full',
className className
)} )}
// We no longer force mounting of inactive tabs // Force mounting of inactive tabs to preserve WebGL contexts
// This prevents the Graph component from being mounted when it's not the active tab forceMount
{...props} {...props}
/> />
)) ))

View File

@@ -140,8 +140,8 @@ const GraphViewer = () => {
// Cleanup function when component unmounts // Cleanup function when component unmounts
return () => { return () => {
// If we're navigating away from the graph tab completely (not just switching tabs) // Only log cleanup, don't actually clean up the WebGL context
// we would clean up here, but for now we want to preserve the WebGL context // This allows the WebGL context to persist across tab switches
console.log('Graph viewer cleanup') console.log('Graph viewer cleanup')
} }
}, [isGraphTabVisible, shouldRender, isFetching]) }, [isGraphTabVisible, shouldRender, isFetching])
@@ -174,11 +174,12 @@ const GraphViewer = () => {
[selectedNode] [selectedNode]
) )
// Only render the SigmaContainer when the tab is visible // Since TabsContent now forces mounting of all tabs, we need to conditionally render
// the SigmaContainer based on visibility to avoid unnecessary rendering
return ( return (
<div className="relative h-full w-full"> <div className="relative h-full w-full">
{/* Only render the SigmaContainer when the tab is visible */}
{isGraphTabVisible ? ( {isGraphTabVisible ? (
// Only render SigmaContainer when tab is visible
<SigmaContainer <SigmaContainer
settings={sigmaSettings} settings={sigmaSettings}
className="!bg-background !size-full overflow-hidden" className="!bg-background !size-full overflow-hidden"