-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Bug Fix][Fabric] Fix onChangeText firing twice when first typing in TextInput #14788
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: main
Are you sure you want to change the base?
[Bug Fix][Fabric] Fix onChangeText firing twice when first typing in TextInput #14788
Conversation
onChangeArgs.eventCount = ++m_nativeEventCount; | ||
emitter->onChange(onChangeArgs); | ||
auto currentText = GetTextFromRichEdit(); | ||
if (currentText != m_lastOnChangeText) { |
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.
This seems like a pretty expensive check. If there was a very large set of text in the textiput, this comparison would get relatively expensive. Is there not some code flow way of determining that the event is not needed?
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
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.
Pull Request Overview
This PR fixes duplicate onChangeText
events in Fabric TextInput
by only emitting the change when the underlying text really changed.
- Added a check for the RichEdit
EM_GETMODIFY
flag before firingonChange
- Clear the modify flag (
EM_SETMODIFY
) after handling to prevent redundant events - Updated prerelease metadata in the JSON manifest
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
vnext/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp | Wrap onChange emission in a modify-flag check |
change/react-native-windows-5060f8b9-f264-472c-a212-48147bd0b243.json | Added prerelease entry with bugfix comment |
Comments suppressed due to low confidence (3)
vnext/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp:1290
- [nitpick] Consider renaming the variable
modified
toisModified
(or similar) to indicate that it holds a boolean-like flag.
LRESULT modified = 0;
vnext/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp:1291
- Consider adding a unit test that simulates typing and ensures
onChange
fires exactly once per actual text change, covering this new deduplication logic.
m_textServices->TxSendMessage(EM_GETMODIFY, 0, 0, &modified);
vnext/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp:1295
- [nitpick] Indent the
onChangeArgs
lines and theemitter->onChange
call to clearly show they are inside theif (modified)
block for better readability.
facebook::react::WindowsTextInputEventEmitter::OnChange onChangeArgs;
@@ -0,0 +1,7 @@ | |||
{ | |||
"type": "prerelease", | |||
"comment": "Fixed OnchangeText bug", |
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.
Update the comment to match the code casing, e.g., "Fixed onChangeText bug"
, for consistency.
"comment": "Fixed OnchangeText bug", | |
"comment": "Fixed onChangeText bug", |
Copilot uses AI. Check for mistakes.
Description
Type of Change
Why
In Fabric TextInput, when a user types a single character, the onChangeText callback was being triggered twice instead of once. This was inconsistent with Paper TextInput behavior and could cause issues in applications that rely on accurate change event counts.
Resolves [https://github.com//issues/12780 ]
What
The new solution uses text-based deduplication - it only emits onChange when the current text differs from the last text for which onChange was emitted. This prevents duplicate onChange events while preserving all expected onChange behavior.
Screenshots
(
)
Testing
E2E test ran succesfully
Changelog
yes
Add a brief summary of the change to use in the release notes for the next release.
Microsoft Reviewers: Open in CodeFlow