Repository navigation
fix(wework): prevent duplicate composer paste - #2053
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe composer’s paste handling now uses a dedicated ProseMirror handler. Tests cover single insertion and multiline rich-text pastes, while English and Chinese documentation describe line-break normalization and mixed clipboard content behavior. ChangesComposer paste behavior
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
wework/src/components/chat/composer/ComposerProseMirrorEditor.tsx (1)
149-160: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winRestore native paste scrolling and metadata.
When overriding ProseMirror's default paste behavior, manually dispatching the transaction loses the native auto-scroll and event metadata. Chaining
scrollIntoView()ensures the caret remains visible if the user pastes a large block of multiline text, and setting the metadata ensures history or input plugins correctly categorize the paste event.♻️ Proposed refactor
handlePaste(view, event) { const text = event.clipboardData?.getData('text/plain') || event.clipboardData?.getData('text') if (!text) return false const paragraph = createComposerDocument(text).firstChild if (!paragraph) return false - view.dispatch(view.state.tr.replaceSelection(new Slice(paragraph.content, 0, 0))) + const tr = view.state.tr.replaceSelection(new Slice(paragraph.content, 0, 0)) + view.dispatch(tr.setMeta('paste', true).setMeta('uiEvent', 'paste').scrollIntoView()) return true }, handleDOMEvents: {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@wework/src/components/chat/composer/ComposerProseMirrorEditor.tsx` around lines 149 - 160, The custom paste handler in handlePaste should preserve native paste behavior by chaining scrollIntoView() onto the replacement transaction and setting the transaction’s paste/input metadata before dispatching it. Keep the existing text extraction, selection replacement, and handled-event flow unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@wework/src/components/chat/composer/ComposerProseMirrorEditor.tsx`:
- Around line 149-160: The custom paste handler in handlePaste should preserve
native paste behavior by chaining scrollIntoView() onto the replacement
transaction and setting the transaction’s paste/input metadata before
dispatching it. Keep the existing text extraction, selection replacement, and
handled-event flow unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: dd5e4c34-ce41-448b-bace-ffc404e6e3d7
📒 Files selected for processing (4)
docs/en/user-guide/chat/managing-tasks.mddocs/zh/user-guide/chat/managing-tasks.mdwework/src/components/chat/composer/ComposerProseMirrorEditor.test.tsxwework/src/components/chat/composer/ComposerProseMirrorEditor.tsx
Summary
handlePastepipeline so one clipboard event produces one editor transactionRoot cause
The composer manually mutated the document from the low-level DOM
pastehook. In Wework's WebKit runtime this could overlap with ProseMirror's own paste lifecycle and intermittently insert the same clipboard payload twice. Rich clipboard payloads also need to use their plain-text representation because the composer schema contains one paragraph with hard breaks.Validation
pnpm --filter wework test— 180 files, 1816 tests passedpnpm --filter wework typecheckScreenshot review chain
The isolated Tauri artifacts are retained under
wework/test-results/ai-verify/review-duplicate-composer-paste/in the verification workspace:01-empty-composer.png02-after-single-paste.png03-after-submit.pngSummary by CodeRabbit