fix(cowork): CopyButton 组件卸载后定时器未清理导致内存泄漏 - #1478
Closed
linlihua wants to merge 1 commit into
Closed
Conversation
The CopyButton component used a bare setTimeout to reset the copied state after 2 seconds. If the component unmounted before the timer fired (e.g. user navigates away or the message list re-renders), the callback tried to call setCopied on an unmounted component, producing a React warning and a minor memory leak. Fix: store the timer ID in a useRef and clear it in a useEffect cleanup function on unmount, following the same pattern already used in MarkdownContent.tsx. Also clear any pending timer before starting a new one on rapid re-clicks. Closes netease-youdao#886
|
This pull request has been inactive for 30 days. It will be automatically closed in 14 days unless there is new activity. If you're still working on this, please leave a comment or push new commits to keep it open. Thank you! |
|
This pull request was automatically closed due to inactivity. Feel free to reopen it if you'd like to continue. |
This was referenced Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题背景
关联 Issue:#886
对话详情页的复制按钮(CopyButton)点击后使用裸 setTimeout 在 2 秒后
重置复制状态。当组件在定时器触发前卸载(如用户快速切换会话、消息列表
重渲染),回调仍会执行 setCopied(false),产生 React「更新已卸载组件」
警告及潜在内存泄漏。
根本原因