diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm index b9a0996bff..6717b9dc5e 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm @@ -680,11 +680,15 @@ NSInvocation *ObjCTurboModule::createMethodInvocation( bool ObjCTurboModule::isMethodSync(TurboModuleMethodValueKind returnType) { + if (isSyncModule_) { + return true; + } + if (returnType == VoidKind && shouldVoidMethodsExecuteSync_) { return true; } - return isSyncModule_ || !(returnType == VoidKind || returnType == PromiseKind); + return !(returnType == VoidKind || returnType == PromiseKind); } ObjCTurboModule::ObjCTurboModule(const InitParams ¶ms) @@ -707,7 +711,9 @@ jsi::Value ObjCTurboModule::invokeObjCMethod( const char *moduleName = name_.c_str(); const char *methodName = methodNameStr.c_str(); - if (isMethodSync(returnType)) { + bool isSyncInvocation = isMethodSync(returnType); + + if (isSyncInvocation) { TurboModulePerfLogger::syncMethodCallStart(moduleName, methodName); } else { TurboModulePerfLogger::asyncMethodCallStart(moduleName, methodName); @@ -715,7 +721,7 @@ jsi::Value ObjCTurboModule::invokeObjCMethod( NSMutableArray *retainedObjectsForInvocation = [NSMutableArray arrayWithCapacity:count + 2]; NSInvocation *inv = createMethodInvocation( - runtime, isMethodSync(returnType), methodName, selector, args, count, retainedObjectsForInvocation); + runtime, isSyncInvocation, methodName, selector, args, count, retainedObjectsForInvocation); jsi::Value returnValue = jsi::Value::undefined(); @@ -730,24 +736,23 @@ jsi::Value ObjCTurboModule::invokeObjCMethod( [retainedObjectsForInvocation addObject:resolveCopy]; [retainedObjectsForInvocation addObject:rejectCopy]; // The return type becomes void in the ObjC side. - performMethodInvocation(runtime, isMethodSync(VoidKind), methodName, inv, retainedObjectsForInvocation); + performMethodInvocation(runtime, isSyncInvocation, methodName, inv, retainedObjectsForInvocation); }); } else { - id result = - performMethodInvocation(runtime, isMethodSync(returnType), methodName, inv, retainedObjectsForInvocation); + id result = performMethodInvocation(runtime, isSyncInvocation, methodName, inv, retainedObjectsForInvocation); - if (isMethodSync(returnType)) { + if (isSyncInvocation) { TurboModulePerfLogger::syncMethodCallReturnConversionStart(moduleName, methodName); } returnValue = convertReturnIdToJSIValue(runtime, methodName, returnType, result); - if (isMethodSync(returnType)) { + if (isSyncInvocation) { TurboModulePerfLogger::syncMethodCallReturnConversionEnd(moduleName, methodName); } } - if (isMethodSync(returnType)) { + if (isSyncInvocation) { TurboModulePerfLogger::syncMethodCallEnd(moduleName, methodName); } else { TurboModulePerfLogger::asyncMethodCallEnd(moduleName, methodName);