Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix: JS timer leaks, DOM growth, and mobile navigation cleanup (#1990)

LearningCircuit29fc55720b57
diff --git a/src/local_deep_research/web/static/js/components/logpanel.js b/src/local_deep_research/web/static/js/components/logpanel.js
index b85df19216..dfe14096e5 100644
--- a/src/local_deep_research/web/static/js/components/logpanel.js
+++ b/src/local_deep_research/web/static/js/components/logpanel.js
@@ -9,6 +9,9 @@
const escapeHtmlFallback = (str) => String(str || '').replace(/[&<>"']/g, (m) => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'})[m]);
const escapeHtml = window.escapeHtml || escapeHtmlFallback;
+ // Maximum number of log entries to keep in DOM to prevent unbounded growth
+ const MAX_LOG_ENTRIES = 500;
+
// Shared state for log panel
window._logPanelState = window._logPanelState || {
expanded: false,
@@ -880,6 +883,15 @@
consoleLogContainer.insertBefore(entry, consoleLogContainer.firstChild);
}
+ // Prune oldest entries if over limit to prevent unbounded DOM growth
+ const entries = consoleLogContainer.querySelectorAll('.ldr-console-log-entry');
+ if (entries.length > MAX_LOG_ENTRIES) {
+ const toRemove = entries.length - MAX_LOG_ENTRIES;
+ for (let i = entries.length - toRemove; i < entries.length; i++) {
+ entries[i].remove();
+ }
+ }
+
// Check if the entry should be visible based on current filter
const currentFilter = window._logPanelState.currentFilter || 'all';
const shouldShow = checkLogVisibility(logLevel.toLowerCase(), currentFilter);
diff --git a/src/local_deep_research/web/static/js/mobile-navigation.js b/src/local_deep_research/web/static/js/mobile-navigation.js
index e6c7062b90..47c70e7223 100644
--- a/src/local_deep_research/web/static/js/mobile-navigation.js
+++ b/src/local_deep_research/web/static/js/mobile-navigation.js
@@ -24,8 +24,7 @@
this.elements = {};
this.initialized = false;
this.closeSheetTimeout = null;
- this.resizeHandler = null;
- this.resizeTimer = null;
+ this.abortController = null;
}
init() {
@@ -225,6 +224,10 @@
}
attachEventListeners() {
+ // Create abort controller for cleanup
+ this.abortController = new AbortController();
+ const signal = this.abortController.signal;
+
// Tab navigation
if (this.elements.nav) {
this.elements.nav.addEventListener('click', (e) => {
@@ -240,7 +243,7 @@
this.navigateToTab(tab.dataset.path);
this.setActiveTab(tabId);
}
- });
+ }, { signal });
}
// Sheet menu items
@@ -250,14 +253,14 @@
if (!item) return;
this.handleSheetItem(item.dataset.action, item.dataset.itemId);
- });
+ }, { signal });
}
// Overlay click to close
if (this.elements.overlay) {
this.elements.overlay.addEventListener('click', () => {
this.closeSheet();
- });
+ }, { signal });
}
// Touch gestures for sheet
@@ -267,8 +270,9 @@
}
attachGestures() {
- if (!this.elements.sheet) return;
+ if (!this.elements.sheet || !this.abortController) return;
+ const signal = this.abortController.signal;
let startY = 0;
let currentY = 0;
let isDragging = false;
@@ -309,16 +313,20 @@
};
if (handle) {
- handle.addEventListener('touchstart', handleTouchStart, { passive: true });
- handle.addEventListener('touchmove', handleTouchMove, { passive: true });
- handle.addEventListener('touchend', handleTouchEnd, { passive: true });
+ handle.addEventListener('touchstart', handleTouchStart, { passive: true, signal });
+ handle.addEventListener('touchmove', handleTouchMove, { passive: true, signal });
+ handle.addEventListener('touchend', handleTouchEnd, { passive: true, signal });
}
}
handleResize() {
- this.resizeHandler = () => {
- clearTimeout(this.resizeTimer);
- this.resizeTimer = setTimeout(() => {
+ if (!this.abortController) return;
+
+ let resizeTimer;
+
+ window.addEventListener('resize', () => {
+ clearTimeout(resizeTimer);
+ resizeTimer = setTimeout(() => {
const wasVisible = this.state.isVisible;
this.checkViewport();
@@ -330,9 +338,7 @@
}
}
}, 250);
- };
-
- window.addEventListener('resize', this.resizeHandler);
+ }, { signal: this.abortController.signal });
}
toggle(show) {
@@ -509,11 +515,11 @@
destroy() {
clearTimeout(this.closeSheetTimeout);
- clearTimeout(this.resizeTimer);
- if (this.resizeHandler) {
- window.removeEventListener('resize', this.resizeHandler);
- this.resizeHandler = null;
+ // Abort all event listeners
+ if (this.abortController) {
+ this.abortController.abort();
+ this.abortController = null;
}
if (this.elements.nav) this.elements.nav.remove();
diff --git a/src/local_deep_research/web/static/js/pages/news.js b/src/local_deep_research/web/static/js/pages/news.js
index 3aa22e28eb..ed849f2096 100644
--- a/src/local_deep_research/web/static/js/pages/news.js
+++ b/src/local_deep_research/web/static/js/pages/news.js
@@ -62,6 +62,8 @@ let lastVisitTime = null;
let seenNewsIds = new Set();
let searchHistory = [];
let autoRefreshInterval = null;
+let priorityCheckInterval = null;
+let refreshIndicatorInterval = null;
let lastRefreshTime = new Date();
let activeTimeFilter = 'all';
let activeImpactThreshold = 0;
@@ -172,15 +174,32 @@ async function initializeNewsPage() {
checkPriorityStatus();
// Set up auto-refresh
- setInterval(checkPriorityStatus, 30000);
+ priorityCheckInterval = setInterval(checkPriorityStatus, 30000);
- // Update visit time when leaving page
+ // Update visit time and clear intervals when leaving page
+ window.addEventListener('pagehide', cleanupNewsPage);
window.addEventListener('beforeunload', () => {
saveVisitTracking();
saveReadStatus();
});
}
+// Cleanup function to clear all intervals when leaving the page
+function cleanupNewsPage() {
+ if (priorityCheckInterval) {
+ clearInterval(priorityCheckInterval);
+ priorityCheckInterval = null;
+ }
+ if (refreshIndicatorInterval) {
+ clearInterval(refreshIndicatorInterval);
+ refreshIndicatorInterval = null;
+ }
+ if (autoRefreshInterval) {
+ clearInterval(autoRefreshInterval);
+ autoRefreshInterval = null;
+ }
+}
+
function setupEventListeners() {
// Search button
const searchBtn = document.getElementById('search-btn');
@@ -2027,8 +2046,11 @@ function startAutoRefresh() {
refreshFeed();
}, refreshInterval);
- // Update indicator every second
- setInterval(updateRefreshIndicator, 1000);
+ // Update indicator every second (clear any existing first)
+ if (refreshIndicatorInterval) {
+ clearInterval(refreshIndicatorInterval);
+ }
+ refreshIndicatorInterval = setInterval(updateRefreshIndicator, 1000);
showAlert('Auto-refresh enabled (every 5 minutes)', 'success');
}
@@ -2038,6 +2060,10 @@ function stopAutoRefresh() {
clearInterval(autoRefreshInterval);
autoRefreshInterval = null;
}
+ if (refreshIndicatorInterval) {
+ clearInterval(refreshIndicatorInterval);
+ refreshIndicatorInterval = null;
+ }
showAlert('Auto-refresh disabled', 'info');
}