From e4a1b005dcba7421f0f620a312cfd0e77ef22400 Mon Sep 17 00:00:00 2001 From: Louis King Date: Sat, 14 Feb 2026 01:44:28 +0000 Subject: [PATCH] Fix clipboard copy error with null target Capture e.currentTarget synchronously before async operations to prevent it from becoming null in async promise handlers. Co-Authored-By: Claude Sonnet 4.5 --- src/meshcore_hub/web/static/js/spa/components.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/meshcore_hub/web/static/js/spa/components.js b/src/meshcore_hub/web/static/js/spa/components.js index 5eb073e..841a329 100644 --- a/src/meshcore_hub/web/static/js/spa/components.js +++ b/src/meshcore_hub/web/static/js/spa/components.js @@ -183,6 +183,9 @@ export function copyToClipboard(e, text) { e.preventDefault(); e.stopPropagation(); + // Capture target element synchronously before async operations + const targetElement = e.currentTarget; + const showSuccess = (target) => { const originalText = target.textContent; target.textContent = 'Copied!'; @@ -196,14 +199,14 @@ export function copyToClipboard(e, text) { // Try modern Clipboard API first if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(text).then(() => { - showSuccess(e.currentTarget); + showSuccess(targetElement); }).catch(err => { console.error('Clipboard API failed:', err); - fallbackCopy(text, e.currentTarget); + fallbackCopy(text, targetElement); }); } else { // Fallback for older browsers or non-secure contexts - fallbackCopy(text, e.currentTarget); + fallbackCopy(text, targetElement); } function fallbackCopy(text, target) {