fix(ui): only show "Copied" feedback when clipboard write succeeds

PR-Agent re-review flagged that `copyText()` swallowed clipboard
errors but the row's `setJustCopied(true)` always fired regardless,
so users in insecure contexts (or with denied clipboard permission)
saw a fake success indicator while nothing was actually copied.

Make `copyText()` return a boolean and gate the "Copied" UI state
on it. When the clipboard write fails, the button stays in its idle
state and the user can retry rather than being misled.

Refs #1138, #1151
This commit is contained in:
Tam Nhu Tran
2026-04-30 15:37:50 -04:00
parent 75cdc02c1f
commit 39ec84a8a9
+7 -3
View File
@@ -31,11 +31,14 @@ function formatHms(timestamp: string): string {
});
}
async function copyText(text: string): Promise<void> {
async function copyText(text: string): Promise<boolean> {
try {
await navigator.clipboard.writeText(text);
return true;
} catch {
// best-effort; clipboard may be unavailable in non-secure contexts
// Insecure context or clipboard permission denied. Caller should NOT
// claim success in the UI when this returns false.
return false;
}
}
@@ -65,7 +68,8 @@ function LogsRowImpl({
const handleCopyRequestId = async (e: React.MouseEvent) => {
e.stopPropagation();
if (!entry.requestId) return;
await copyText(entry.requestId);
const ok = await copyText(entry.requestId);
if (!ok) return;
setJustCopied(true);
window.setTimeout(() => setJustCopied(false), 1200);
};