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
This commit is contained in:
3nd3r 2026-04-12 12:56:33 -05:00
parent b38eb01e27
commit 496701c713
1 changed files with 7 additions and 8 deletions

View File

@ -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");
};
});
}