From 72605aed21e63dc8626f3ec367eb91155a52a7a6 Mon Sep 17 00:00:00 2001 From: MarekWo Date: Tue, 30 Dec 2025 09:21:30 +0100 Subject: [PATCH] fix(ui): Add null check for cleanupBtn to prevent JS errors on main page The cleanupBtn element only exists on the contact management page, not on the main chat page. This was causing JavaScript to crash with 'cannot access property addEventListener of null' error, preventing messages from loading. Added null check before attaching event listener. --- app/static/js/app.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/static/js/app.js b/app/static/js/app.js index 925816c..e2367b2 100644 --- a/app/static/js/app.js +++ b/app/static/js/app.js @@ -99,10 +99,13 @@ function setupEventListeners() { } }); - // Cleanup contacts button - document.getElementById('cleanupBtn').addEventListener('click', function() { - cleanupContacts(); - }); + // Cleanup contacts button (only exists on contact management page) + const cleanupBtn = document.getElementById('cleanupBtn'); + if (cleanupBtn) { + cleanupBtn.addEventListener('click', function() { + cleanupContacts(); + }); + } // Track user scrolling const container = document.getElementById('messagesContainer');