diff --git a/React/CxxModule/RCTCxxUtils.mm b/React/CxxModule/RCTCxxUtils.mm index 331e0bfaf5..73951be812 100644 --- a/React/CxxModule/RCTCxxUtils.mm +++ b/React/CxxModule/RCTCxxUtils.mm @@ -46,12 +46,6 @@ std::vector> createNativeModules(NSArray> nativeModules; for (RCTModuleData *moduleData in modules) { if ([moduleData.moduleClass isSubclassOfClass:[RCTCxxModule class]]) { - // If a module does not support automatic instantiation, and - // wasn't provided as an extra module, it may not have an - // instance. If so, skip it. - if (![moduleData hasInstance]) { - continue; - } nativeModules.emplace_back(std::make_unique( instance, [moduleData.name UTF8String], diff --git a/ReactCommon/cxxreact/CxxNativeModule.cpp b/ReactCommon/cxxreact/CxxNativeModule.cpp index 40d37f1a0e..52a1469fe9 100644 --- a/ReactCommon/cxxreact/CxxNativeModule.cpp +++ b/ReactCommon/cxxreact/CxxNativeModule.cpp @@ -64,6 +64,10 @@ std::vector CxxNativeModule::getMethods() { folly::dynamic CxxNativeModule::getConstants() { lazyInit(); + if (!module_) { + return nullptr; + } + folly::dynamic constants = folly::dynamic::object(); for (auto& pair : module_->getConstants()) { constants.insert(std::move(pair.first), std::move(pair.second)); @@ -161,13 +165,17 @@ MethodCallResult CxxNativeModule::callSerializableNativeHook( } void CxxNativeModule::lazyInit() { - if (module_) { + if (module_ || !provider_) { return; } + // TODO 17216751: providers should never return null modules module_ = provider_(); - methods_ = module_->getMethods(); - module_->setInstance(instance_); + provider_ = nullptr; + if (module_) { + methods_ = module_->getMethods(); + module_->setInstance(instance_); + } } } diff --git a/ReactCommon/cxxreact/ModuleRegistry.cpp b/ReactCommon/cxxreact/ModuleRegistry.cpp index 4a7dcb8014..7fda3c75cc 100644 --- a/ReactCommon/cxxreact/ModuleRegistry.cpp +++ b/ReactCommon/cxxreact/ModuleRegistry.cpp @@ -105,7 +105,7 @@ folly::Optional ModuleRegistry::getConfig(const std::string& name) } } - if (config.size() == 1) { + if (config.size() == 2 && config[1].empty()) { // no constants or methods return nullptr; } else {