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