Skip to content

[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

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

HariniMalothu17
Copy link
Contributor

@HariniMalothu17 HariniMalothu17 commented Jun 17, 2025

Description

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

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

(image)

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

@HariniMalothu17 HariniMalothu17 marked this pull request as ready for review June 17, 2025 12:00
@HariniMalothu17 HariniMalothu17 requested a review from a team as a code owner June 17, 2025 12:00
@HariniMalothu17 HariniMalothu17 changed the title [Fabric] Fix onChangeText firing twice when first typing in TextInput [Bug Fix][Fabric] Fix onChangeText firing twice when first typing in TextInput Jun 17, 2025
onChangeArgs.eventCount = ++m_nativeEventCount;
emitter->onChange(onChangeArgs);
auto currentText = GetTextFromRichEdit();
if (currentText != m_lastOnChangeText) {
Copy link
Contributor

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?

@vineethkuttan
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@HariniMalothu17 HariniMalothu17 requested a review from Copilot June 26, 2025 07:11
Copy link
Contributor

@Copilot Copilot AI left a 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 firing onChange
  • 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 to isModified (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 the emitter->onChange call to clearly show they are inside the if (modified) block for better readability.
        facebook::react::WindowsTextInputEventEmitter::OnChange onChangeArgs;

@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Fixed OnchangeText bug",
Copy link
Preview

Copilot AI Jun 26, 2025

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.

Suggested change
"comment": "Fixed OnchangeText bug",
"comment": "Fixed onChangeText bug",

Copilot uses AI. Check for mistakes.

@HariniMalothu17 HariniMalothu17 self-assigned this Jun 30, 2025
@HariniMalothu17 HariniMalothu17 marked this pull request as draft June 30, 2025 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants