Skip to content

Commit c4ab9c0

Browse files
author
Protik Biswas
committed
chnaging the logic on synchronization between JS and Native side
1 parent 8a5fa68 commit c4ab9c0

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

vnext/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,12 @@ void WindowsTextInputComponentView::HandleCommand(
541541
std::optional<winrt::hstring> text;
542542

543543
winrt::Microsoft::ReactNative::ReadArgs(args.CommandArgs(), eventCount, text, begin, end);
544-
// Only accept text updates that match the current native event count
545-
// This prevents race conditions and maintains proper state synchronization
546-
if (eventCount >= m_nativeEventCount) {
544+
// Accept text updates that match current event count, or are within a reasonable
545+
// tolerance for async JS responses to recent events (like onSubmitEditing)
546+
bool isCurrentEvent = eventCount >= m_nativeEventCount;
547+
bool isRecentAsyncResponse = (m_nativeEventCount - eventCount) <= 2; // Allow up to 2 events behind
548+
549+
if (isCurrentEvent || isRecentAsyncResponse) {
547550
m_comingFromJS = true;
548551
{
549552
if (text.has_value()) {
@@ -956,12 +959,8 @@ void WindowsTextInputComponentView::OnCharacterReceived(
956959
auto emitter = std::static_pointer_cast<const facebook::react::WindowsTextInputEventEmitter>(m_eventEmitter);
957960
facebook::react::WindowsTextInputEventEmitter::OnSubmitEditing onSubmitEditingArgs;
958961
onSubmitEditingArgs.text = GetTextFromRichEdit();
959-
// Don't increment event count yet - let JS respond with current count first
960-
onSubmitEditingArgs.eventCount = m_nativeEventCount;
962+
onSubmitEditingArgs.eventCount = ++m_nativeEventCount;
961963
emitter->onSubmitEditing(onSubmitEditingArgs);
962-
963-
// Increment after emitting to allow JS to respond with matching count
964-
++m_nativeEventCount;
965964
}
966965

967966
if (m_clearTextOnSubmit) {

0 commit comments

Comments
 (0)