-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
name: Bug Report
description: Missing setTimeout cleanup in useCopyToClipboard hook
labels: ["bug", "memory-leak", "guaranteed", "react", "auto-generated"]
Thanks for your report! Please check existing issues first:
👉 https://github.com/RooCodeInc/Roo-Code/issues
App Version
N/A (Static Analysis - Detected in clipboard_44)
API Provider
Not Applicable / Other
Model Used
N/A (UI Utility Hook - useCopyToClipboard)
🔁 Steps to Reproduce
- Setup: A React component utilizing the
useCopyToClipboardhook fromwebview-ui/src/utils/clipboard.ts. - Exact actions:
- Call the
copyWithFeedbackfunction returned by the hook. - The component unmounts before the
feedbackDuration(default 2000ms) elapses.
- Call the
- What happened after each step:
- The
setTimeoutscheduled at line 44 inclipboard.tsto hide the feedback message (setShowCopyFeedback(false)) fires after the component has unmounted. - This results in a React warning: "Can't perform a React state update on an unmounted component."
- The
💥 Outcome Summary
Expected the setTimeout in useCopyToClipboard to be cleared if the component unmounts. However, the timeout callback attempts a state update on an unmounted component, causing a warning and potential instability.
📄 Relevant Logs or Errors (Optional)
Summary:
The
useCopyToClipboardhook'scopyWithFeedbackfunction schedules asetTimeoutat line 44 to hide a feedback message. This timeout is not cleared if the component using the hook unmounts before the timeout completes.If
copyWithFeedbackis called and the component unmounts before thefeedbackDuration(default 2000ms) elapses, thesetTimeoutcallback will attempt to callsetShowCopyFeedback(false)on an unmounted component. This leads to a React warning ("Can't perform a React state update on an unmounted component") and can cause unexpected behavior.
The issue is in webview-ui/src/utils/clipboard.ts around line 44.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status