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

File diff suppressed because one or more lines are too long

View File

@@ -8,7 +8,7 @@
<link rel="icon" type="image/svg+xml" href="logo.png" /> <link rel="icon" type="image/svg+xml" href="logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lightrag</title> <title>Lightrag</title>
<script type="module" crossorigin src="/webui/assets/index-CSrxfS-k.js"></script> <script type="module" crossorigin src="/webui/assets/index-BiPN9eZH.js"></script>
<link rel="stylesheet" crossorigin href="/webui/assets/index-mPRIIErN.css"> <link rel="stylesheet" crossorigin href="/webui/assets/index-mPRIIErN.css">
</head> </head>
<body> <body>

View File

@@ -151,9 +151,17 @@ const GraphViewer = () => {
// Clean up sigma instance when component unmounts // Clean up sigma instance when component unmounts
useEffect(() => { useEffect(() => {
return () => { return () => {
// Clear the sigma instance when component unmounts const sigma = useGraphStore.getState().sigmaInstance;
useGraphStore.getState().setSigmaInstance(null); if (sigma) {
console.log('Cleared sigma instance on unmount'); 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);
}
}
}; };
}, []); }, []);

View File

@@ -19,21 +19,21 @@ class NavigationService {
*/ */
resetAllApplicationState() { resetAllApplicationState() {
console.log('Resetting all application state...'); console.log('Resetting all application state...');
// Clear authentication state // Clear authentication state
localStorage.removeItem('LIGHTRAG-API-TOKEN'); localStorage.removeItem('LIGHTRAG-API-TOKEN');
sessionStorage.clear(); sessionStorage.clear();
useAuthStore.getState().logout(); useAuthStore.getState().logout();
// Reset graph state // Reset graph state
const graphStore = useGraphStore.getState(); const graphStore = useGraphStore.getState();
graphStore.reset(); graphStore.reset();
graphStore.setGraphDataFetchAttempted(false); graphStore.setGraphDataFetchAttempted(false);
graphStore.setLabelsFetchAttempted(false); graphStore.setLabelsFetchAttempted(false);
// Reset backend state // Reset backend state
useBackendState.getState().clear(); useBackendState.getState().clear();
// Reset retrieval history while preserving other user preferences // Reset retrieval history while preserving other user preferences
useSettingsStore.getState().setRetrievalHistory([]); useSettingsStore.getState().setRetrievalHistory([]);
} }
@@ -45,7 +45,7 @@ class NavigationService {
navigateToLogin() { navigateToLogin() {
// Reset state before navigation // Reset state before navigation
this.resetAllApplicationState(); this.resetAllApplicationState();
if (this.navigate) { if (this.navigate) {
this.navigate('/login'); this.navigate('/login');
} }