Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"comment": "Fix TextInput clearTextOnSubmit-style behavior regression in Fabric architecture",
"type": "prerelease",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <Fabric/platform/react/renderer/graphics/PlatformColorUtils.h>
#include <Utils/ThemeUtils.h>
#include <Utils/ValueUtils.h>
#include <react/renderer/attributedstring/AttributedString.h>
#include <react/renderer/attributedstring/AttributedStringBox.h>
#include <react/renderer/components/textinput/TextInputState.h>
#include <react/renderer/graphics/HostPlatformColor.h>
#include <react/renderer/textlayoutmanager/WindowsTextLayoutManager.h>
Expand Down Expand Up @@ -541,7 +543,10 @@ void WindowsTextInputComponentView::HandleCommand(
std::optional<winrt::hstring> text;

winrt::Microsoft::ReactNative::ReadArgs(args.CommandArgs(), eventCount, text, begin, end);
if (eventCount >= m_nativeEventCount) {
// Allow text updates that are very close to the current native event count
// This handles the case where JavaScript immediately calls setValue during onSubmitEditing
// In that case, eventCount might be one less than m_nativeEventCount due to timing
if (eventCount >= m_nativeEventCount - 1) {
Copy link
Contributor

@anupriya13 anupriya13 Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not able to understand on how this is related to pressing enter for clearOnSubmit? What about all existing worflows for events?

Copy link
Contributor

@anupriya13 anupriya13 Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try removing this change and check if your code is working fine for clearOnSubmit?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this seems like it would cause us to get into all kinds of bad states, if we start listening to JS commands when native is an event behind.

m_comingFromJS = true;
{
if (text.has_value()) {
Expand Down Expand Up @@ -961,6 +966,13 @@ void WindowsTextInputComponentView::OnCharacterReceived(
if (m_clearTextOnSubmit) {
// clear text from RichEdit
m_textServices->TxSetText(L"");
// Also update the state to reflect the cleared text
// This ensures consistency between native and JS state
auto data = m_state->getData();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should already happen through WindowsTextInputComponentView::OnTextUpdated. -- Why are we not hitting that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that TxSetText(L"") should normally trigger [EN_CHANGE] → OnTextUpdated(). However, there are several timing and context issues that make the manual state update necessary. One reason why we are not hitting the case I believe is that OnTextUpdated() method has a condition if (m_eventEmitter && !m_comingFromJS) that prevents event emission when m_comingFromJS is true. While we're not setting m_comingFromJS = true here, there might be other state flags or timing issues that could suppress the automatic notification.

data.attributedStringBox = facebook::react::AttributedStringBox{facebook::react::AttributedString{}};
data.mostRecentEventCount = m_nativeEventCount;

m_state->updateState(std::move(data));
}
return;
}
Expand Down
Loading