Spaces:
Build error
Build error
Commit ·
4d6372a
1
Parent(s): 4d11956
fix(JS-4,FEED-4): stop D3 simulation and close WebSocket on route navigation -- prevents CPU/memory leak
Browse files- frontend/js/router.js +12 -0
frontend/js/router.js
CHANGED
|
@@ -7,6 +7,18 @@ const Router = {
|
|
| 7 |
},
|
| 8 |
|
| 9 |
navigate: (path, pushState = true) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
if (pushState) {
|
| 11 |
window.history.pushState({}, "", `#${path}`);
|
| 12 |
}
|
|
|
|
| 7 |
},
|
| 8 |
|
| 9 |
navigate: (path, pushState = true) => {
|
| 10 |
+
// JS-4 FIX: stop D3 force simulation before clearing main DOM.
|
| 11 |
+
// Without this, the simulation timer keeps running indefinitely after
|
| 12 |
+
// navigation, consuming CPU and holding references to removed elements.
|
| 13 |
+
if (window.GraphRenderer && GraphRenderer._currentSimulation) {
|
| 14 |
+
GraphRenderer._currentSimulation.stop();
|
| 15 |
+
GraphRenderer._currentSimulation = null;
|
| 16 |
+
}
|
| 17 |
+
// FEED-4 FIX: close open WebSocket feed socket on navigation
|
| 18 |
+
if (window._activeFeedSocket && window._activeFeedSocket.readyState <= 1) {
|
| 19 |
+
window._activeFeedSocket.close();
|
| 20 |
+
window._activeFeedSocket = null;
|
| 21 |
+
}
|
| 22 |
if (pushState) {
|
| 23 |
window.history.pushState({}, "", `#${path}`);
|
| 24 |
}
|