From 496701c713acfa9fb4b6adec02253a4ebb76b3e9 Mon Sep 17 00:00:00 2001 From: 3nd3r Date: Sun, 12 Apr 2026 12:56:33 -0500 Subject: [PATCH] Fix #9: Fix context menu breaking after first use - Remove cloneNode/replaceWith pattern that orphaned the reference - Re-bind onclick handlers directly on the existing DOM node - Context menu now works reliably on every right-click --- static/chat.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/static/chat.js b/static/chat.js index 0bde142..a7efa8c 100644 --- a/static/chat.js +++ b/static/chat.js @@ -528,16 +528,15 @@ function showContextMenu(e, user) { } }); - // Cleanup previous listeners - const newMenu = contextMenu.cloneNode(true); - contextMenu.replaceWith(newMenu); - - // Add new listeners - newMenu.querySelectorAll(".menu-item").forEach(item => { + // Store target for click handler (uses event delegation below) + contextMenu._targetUser = user.username; + + // Remove old inline onclick handlers and re-bind + contextMenu.querySelectorAll(".menu-item").forEach(item => { item.onclick = () => { const action = item.dataset.action; - executeMenuAction(action, user.username); - newMenu.classList.add("hidden"); + executeMenuAction(action, contextMenu._targetUser); + contextMenu.classList.add("hidden"); }; }); }