Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ import {
LockOpenIcon,
Undo2Icon,
XIcon,
CopyIcon,
CheckIcon,
} from "lucide-react";
import { Button } from "./ui/button";
import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "./ui/select";
Expand Down Expand Up @@ -2333,6 +2335,28 @@ const PendingApprovalsPanel = memo(function PendingApprovalsPanel({
);
});

const MessageCopyButton = memo(function MessageCopyButton({ text }: { text: string }) {
const [copied, setCopied] = useState(false);

const handleCopy = useCallback(() => {
void navigator.clipboard.writeText(text);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
Comment on lines +2341 to +2344
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Handle clipboard API errors and clean up timeout on unmount.

navigator.clipboard.writeText can reject (permission denied, insecure context). Currently, failures are silently ignored and the user sees "copied" feedback regardless. Additionally, the timeout should be cleaned up if the component unmounts.

🛡️ Proposed fix
 const MessageCopyButton = memo(function MessageCopyButton({ text }: { text: string }) {
   const [copied, setCopied] = useState(false);
 
   const handleCopy = useCallback(() => {
-    void navigator.clipboard.writeText(text);
-    setCopied(true);
-    setTimeout(() => setCopied(false), 2000);
+    navigator.clipboard.writeText(text).then(
+      () => setCopied(true),
+      () => {
+        // Optionally show error feedback or silently fail
+      }
+    );
   }, [text]);
+
+  useEffect(() => {
+    if (!copied) return;
+    const timer = setTimeout(() => setCopied(false), 2000);
+    return () => clearTimeout(timer);
+  }, [copied]);
 
   return (
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/web/src/components/ChatView.tsx` around lines 2341 - 2344, handleCopy
currently calls navigator.clipboard.writeText without handling rejections and
always sets setCopied(true), and the timeout is never cleared on unmount; update
handleCopy to await or use .then/.catch on navigator.clipboard.writeText(text)
and only call setCopied(true) when the promise resolves, log or surface the
error on rejection and avoid setting copied on failure, store the timeout id in
a ref (e.g., copyTimeoutRef) and use clearTimeout(copyTimeoutRef.current) before
setting a new timeout, and add a cleanup (in a useEffect return) to clear the
timeout on unmount; reference handleCopy, navigator.clipboard.writeText,
setCopied and the timeout logic when making changes.

}, [text]);

return (
<Button
type="button"
size="xs"
variant="outline"
onClick={handleCopy}
title="Copy message"
>
{copied ? <CheckIcon className="size-3 text-success" /> : <CopyIcon className="size-3" />}
</Button>
);
});

interface MessagesTimelineProps {
hasMessages: boolean;
isWorking: boolean;
Expand Down Expand Up @@ -2549,7 +2573,7 @@ const MessagesTimeline = memo(function MessagesTimeline({
const canRevertAgentWork = revertTurnCountByUserMessageId.has(row.message.id);
return (
<div className="flex justify-end">
<div className="max-w-[80%] rounded-2xl rounded-br-sm border border-border bg-secondary px-4 py-3">
<div className="group relative max-w-[80%] rounded-2xl rounded-br-sm border border-border bg-secondary px-4 py-3">
{userImages.length > 0 && (
<div className="mb-2 grid max-w-[420px] grid-cols-2 gap-2">
{userImages.map(
Expand Down Expand Up @@ -2583,17 +2607,21 @@ const MessagesTimeline = memo(function MessagesTimeline({
</pre>
)}
<div className="mt-1.5 flex items-center justify-end gap-2">
{canRevertAgentWork && (
<Button
type="button"
size="xs"
variant="outline"
disabled={isRevertingCheckpoint || isWorking}
onClick={() => onRevertUserMessage(row.message.id)}
>
<Undo2Icon className="size-3" />
</Button>
)}
<div className="flex items-center gap-1.5 opacity-0 transition-opacity duration-200 focus-within:opacity-100 group-hover:opacity-100">
{row.message.text && <MessageCopyButton text={row.message.text} />}
{canRevertAgentWork && (
<Button
type="button"
size="xs"
variant="outline"
disabled={isRevertingCheckpoint || isWorking}
onClick={() => onRevertUserMessage(row.message.id)}
title="Revert to this message"
>
<Undo2Icon className="size-3" />
</Button>
)}
</div>
<p className="text-right text-[10px] text-muted-foreground/30">
{formatTimestamp(row.message.createdAt)}
</p>
Expand Down