Skip to content

Commit fbc4208

Browse files
committed
[core] Fix sigma killing process when SigmaContainer is unmount
If `SigmaContainer` is unmount, the sigma kill process was not called. The GC should handle it, but in the case where a graph is given to the component and is still alive, GC do nothing.
1 parent d4bb434 commit fbc4208

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Version 5.0.3
4+
5+
### Fixes
6+
7+
- Fix `sigma` killing process when `SigmaContainer` is unmount.
8+
39
## Version 5.0.2
410

511
### Fixes

packages/core/src/components/SigmaContainer.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,27 @@ const SigmaContainerComponent = <
9090
* => create sigma
9191
*/
9292
useEffect(() => {
93-
setSigma((prev) => {
94-
let instance: Sigma<N, E, G> | null = null;
95-
if (containerRef.current !== null) {
96-
let sigGraph = new Graph<N, E, G>();
97-
if (graph) {
98-
sigGraph = typeof graph === 'function' ? new graph() : graph;
99-
}
93+
let instance: Sigma<N, E, G> | null = null;
94+
if (containerRef.current !== null) {
95+
let sigGraph = new Graph<N, E, G>();
96+
if (graph) {
97+
sigGraph = typeof graph === 'function' ? new graph() : graph;
98+
}
99+
instance = new Sigma(sigGraph, containerRef.current, sigmaSettings);
100+
setSigma((prev) => {
100101
let prevCameraState: CameraState | null = null;
101102
if (prev) {
102103
prevCameraState = prev.getCamera().getState();
103-
prev.kill();
104104
}
105-
instance = new Sigma(sigGraph, containerRef.current, sigmaSettings);
106-
if (prevCameraState) instance.getCamera().setState(prevCameraState);
105+
if (prevCameraState) instance!.getCamera().setState(prevCameraState);
106+
return instance;
107+
});
108+
}
109+
return () => {
110+
if (instance) {
111+
instance.kill();
107112
}
108-
return instance;
109-
});
113+
};
110114
}, [containerRef, graph, sigmaSettings]);
111115

112116
/**

0 commit comments

Comments
 (0)