Skip to content

fix(composer): ensure pasted text is always captured via React state (#5446)#5455

Merged
SivanCola merged 3 commits into
esengine:main-v2from
ttmouse:fix/paste-multiline-5446
Jun 30, 2026
Merged

fix(composer): ensure pasted text is always captured via React state (#5446)#5455
SivanCola merged 3 commits into
esengine:main-v2from
ttmouse:fix/paste-multiline-5446

Conversation

@ttmouse

@ttmouse ttmouse commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

修复内容

Fixes #5446

问题描述

粘贴多行文本到输入框后,模型回复表示未收到粘贴的内容。原因是粘贴处理器对短文本(<20行)依赖浏览器默认粘贴行为,但 React 受控组件的 reconciliation 机制可能在 onChange 事件触发前用旧状态覆盖 textarea 的 DOM value,导致粘贴内容丢失。

变更说明

  1. 粘贴处理器 (): 不再分情况处理,对所有粘贴操作都使用 阻止浏览器默认行为,通过 React 手动插入文本。这样确保 value 始终由 React 状态驱动,消除了受控组件的竞态条件。

  2. 提交函数 (): 从 、、、 读取最新值,而非从 state 闭包变量读取,增加第二层防御防止陈旧闭包问题。

验证

  • TypeScript 编译无新错误
  • Go build 通过
  • 改动量: 1 个文件, +43/-23 行

影响范围

仅修改 desktop/frontend/src/components/Composer.tsx,不影响其他模块。

@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development desktop Wails desktop app (desktop/**) labels Jun 27, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread desktop/frontend/src/components/Composer.tsx Outdated
Comment thread desktop/frontend/src/components/Composer.tsx Outdated
…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.
@ttmouse ttmouse force-pushed the fix/paste-multiline-5446 branch from d8e436b to 1e3ef27 Compare June 28, 2026 05:26
ttmouse and others added 2 commits June 28, 2026 13:30
…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>
@SivanCola SivanCola merged commit d60d0b0 into esengine:main-v2 Jun 30, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

desktop Wails desktop app (desktop/**) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 粘贴多行文本时模型无法接收到内容

2 participants