diff --git a/ReactCommon/cxxreact/NativeToJsBridge.cpp b/ReactCommon/cxxreact/NativeToJsBridge.cpp index 5c4399766c0704..8c6babfbf4e842 100644 --- a/ReactCommon/cxxreact/NativeToJsBridge.cpp +++ b/ReactCommon/cxxreact/NativeToJsBridge.cpp @@ -52,6 +52,8 @@ class JsToNativeBridge : public react::ExecutorDelegate { "native module calls cannot be completed with no native modules"; ExecutorToken token = m_nativeToJs->getTokenForExecutor(executor); m_nativeQueue->runOnQueue([this, token, calls=std::move(calls), isEndOfBatch] () mutable { + m_batchHadNativeModuleCalls = m_batchHadNativeModuleCalls || !calls.empty(); + // An exception anywhere in here stops processing of the batch. This // was the behavior of the Android bridge, and since exception handling // terminates the whole bridge, there's not much point in continuing. @@ -60,7 +62,10 @@ class JsToNativeBridge : public react::ExecutorDelegate { token, call.moduleId, call.methodId, std::move(call.arguments), call.callId); } if (isEndOfBatch) { - m_callback->onBatchComplete(); + if (m_batchHadNativeModuleCalls) { + m_callback->onBatchComplete(); + m_batchHadNativeModuleCalls = false; + } m_callback->decrementPendingJSCalls(); } }); @@ -88,6 +93,7 @@ class JsToNativeBridge : public react::ExecutorDelegate { std::shared_ptr m_registry; std::unique_ptr m_nativeQueue; std::shared_ptr m_callback; + bool m_batchHadNativeModuleCalls = false; }; NativeToJsBridge::NativeToJsBridge(