Uh oh!
There was an error while loading. Please reload this page.
fix: trigger onChange twice when using IME input - #78
Conversation
Walkthrough在 src/TextArea.tsx 中为 triggerChange 方法添加了 ChangeEventInfo 参数以区分事件源,并在组合事件结束时添加了条件守卫以防止意外的状态变化。同时在 src/interface.ts 中新增导出接口 ChangeEventInfo。 Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant TextArea as TextArea Component
participant triggerChange as triggerChange
participant onChange as onChange Handler
User->>TextArea: Composition End Event
TextArea->>triggerChange: Call with info.source='compositionEnd'
alt source === 'compositionEnd'
triggerChange->>triggerChange: Skip value update (guard)
end
triggerChange->>onChange: Emit change event
User->>TextArea: Regular Change Event
TextArea->>triggerChange: Call with info.source='change'
triggerChange->>triggerChange: Process value update
triggerChange->>onChange: Emit change event
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 分钟
Possibly related issues
Poem
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used🧬 Code graph analysis (1)src/TextArea.tsx (1)
🔇 Additional comments (5)
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 |
Summary of ChangesHello @SocietyNiu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a bug where the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request aims to fix an issue where onChange is triggered twice when using an IME by introducing a source to the change event. While the approach is sound, the current implementation has a logical flaw. The fix works correctly when maxLength is not a factor, but it fails to prevent the double trigger when maxLength is active and exceeded, as the new logic is bypassed. I've provided a suggestion to correct this logic to ensure onChange is only fired once in all scenarios.
SocietyNiu
commented
Nov 4, 2025
nrps9909
left a comment
There was a problem hiding this comment.
Approved exact head ad936811b5a424b0c1b4c6bfabe959d8735bf51b.
I independently added a temporary regression matrix on this exact head and removed it after validation. It confirmed:
- one ordinary IME commit emits
onChangeonce instead of twice; onCompositionEndstill fires once;- when
exceedFormatteractually truncates composed input, the raw composition value and corrected value are both reported, matching@rc-component/inputbehavior; - the complete suite passes with the temporary matrix: 6 suites, 54 tests, 9 snapshots;
- focused ESLint, Prettier, and diff checks pass.
The implementation is behaviorally sound. I recommend committing equivalent regression coverage before merge because the current PR changes a subtle browser event sequence without adding tests.
AI assistance disclosure: Codex was used to trace the event order, compare the merged rc-input implementation, construct the temporary exact-head tests, and draft this review. I verified the head and results before approving.

This PR addresses issue #77 .

The same solution as react-component/input#61.
Summary by CodeRabbit
Bug Fixes