fix(composer): ensure pasted text is always captured via React state (#5446)#5455
Merged
Merged
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d8e436b032
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…sengine#5446) The paste handler previously relied on the browser's default paste behavior for short multi-line text (<20 lines), only preventing default for long pastes that get folded into collapsible blocks. This creates a race condition in React's controlled-input reconciliation: a concurrent re-render can overwrite the textarea DOM value with stale state before onChange fires, losing the pasted content entirely (WebView2 / Windows). Fix: always preventDefault() in the paste handler and insert text through React setText() — both for folded long pastes and raw short pastes — so the value is always driven by React state, not the DOM. Also switch submit() to read from textRef.current / attachmentsRef.current / workspaceRefsRef.current / sessionRefsRef.current instead of state variables, providing a second defense layer against stale closures.
d8e436b to
1e3ef27
Compare
…esengine#5446) Address Codex review feedback: - Reset prompt history navigation state in the short-paste branch so context-menu pastes don't corrupt prompt-history editing - Normalize \r\n to \n for caret position calculation (Windows)
Co-authored-by: SivanCola <32437197+SivanCola@users.noreply.github.com>
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.
修复内容
Fixes #5446
问题描述
粘贴多行文本到输入框后,模型回复表示未收到粘贴的内容。原因是粘贴处理器对短文本(<20行)依赖浏览器默认粘贴行为,但 React 受控组件的 reconciliation 机制可能在 onChange 事件触发前用旧状态覆盖 textarea 的 DOM value,导致粘贴内容丢失。
变更说明
粘贴处理器 (): 不再分情况处理,对所有粘贴操作都使用 阻止浏览器默认行为,通过 React 手动插入文本。这样确保 value 始终由 React 状态驱动,消除了受控组件的竞态条件。
提交函数 (): 从 、、、 读取最新值,而非从 state 闭包变量读取,增加第二层防御防止陈旧闭包问题。
验证
影响范围
仅修改 desktop/frontend/src/components/Composer.tsx,不影响其他模块。