-
Notifications
You must be signed in to change notification settings - Fork 45
fix: trigger onChange twice when using IME input #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.

This PR addresses issue #77 .

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