Skip to content

Commit 3ac5667

Browse files
Merge pull request #118 from ipnet-mesh/feat/node-list-tag-improvements
Fix clipboard copy error with null target
2 parents 27adc6e + c8c53b2 commit 3ac5667

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/meshcore_hub/web/static/js/spa/components.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ export function copyToClipboard(e, text) {
183183
e.preventDefault();
184184
e.stopPropagation();
185185

186+
// Capture target element synchronously before async operations
187+
const targetElement = e.currentTarget;
188+
186189
const showSuccess = (target) => {
187190
const originalText = target.textContent;
188191
target.textContent = 'Copied!';
@@ -196,14 +199,14 @@ export function copyToClipboard(e, text) {
196199
// Try modern Clipboard API first
197200
if (navigator.clipboard && navigator.clipboard.writeText) {
198201
navigator.clipboard.writeText(text).then(() => {
199-
showSuccess(e.currentTarget);
202+
showSuccess(targetElement);
200203
}).catch(err => {
201204
console.error('Clipboard API failed:', err);
202-
fallbackCopy(text, e.currentTarget);
205+
fallbackCopy(text, targetElement);
203206
});
204207
} else {
205208
// Fallback for older browsers or non-secure contexts
206-
fallbackCopy(text, e.currentTarget);
209+
fallbackCopy(text, targetElement);
207210
}
208211

209212
function fallbackCopy(text, target) {

0 commit comments

Comments
 (0)