From a533ee8aea500326dae6dcd4144ce7d3fbba8ff8 Mon Sep 17 00:00:00 2001 From: Vercel Date: Tue, 13 Jan 2026 08:46:36 +0000 Subject: [PATCH] Fix: The handleCopy function fails to handle errors from navigator.clipboard.writeText(), causing unhandled exceptions and misleading UI feedback when clipboard operations fail. Co-authored-by: ctate --- docs/src/components/copy-button.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/src/components/copy-button.tsx b/docs/src/components/copy-button.tsx index 37e5bbe..97930ca 100644 --- a/docs/src/components/copy-button.tsx +++ b/docs/src/components/copy-button.tsx @@ -10,9 +10,14 @@ export function CopyButton({ code }: CopyButtonProps) { const [copied, setCopied] = useState(false); const handleCopy = async () => { - await navigator.clipboard.writeText(code); - setCopied(true); - setTimeout(() => setCopied(false), 2000); + try { + await navigator.clipboard.writeText(code); + setCopied(true); + setTimeout(() => setCopied(false), 2000); + } catch (error) { + console.error("Failed to copy to clipboard:", error); + // Optionally, you could set an error state or show a toast notification here + } }; return (