Improve cleanup and state reset logic in GraphViewer and NavigationService.

- Add proper Sigma instance cleanup on unmount
- Ensure error handling for Sigma cleanup
This commit is contained in:
yangdx
2025-03-19 01:03:24 +08:00
parent 77cb9da384
commit bc4c16b06a
4 changed files with 141 additions and 133 deletions

View File

@@ -151,9 +151,17 @@ const GraphViewer = () => {
// Clean up sigma instance when component unmounts
useEffect(() => {
return () => {
// Clear the sigma instance when component unmounts
useGraphStore.getState().setSigmaInstance(null);
console.log('Cleared sigma instance on unmount');
const sigma = useGraphStore.getState().sigmaInstance;
if (sigma) {
try {
// 销毁sigma实例这会自动清理WebGL上下文
sigma.kill();
useGraphStore.getState().setSigmaInstance(null);
console.log('Cleared sigma instance on unmount');
} catch (error) {
console.error('Error cleaning up sigma instance:', error);
}
}
};
}, []);