mirror of
https://github.com/ipnet-mesh/meshcore-hub.git
synced 2026-03-28 17:42:56 +01:00
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user