From a966ddd772ce40c99bd2f249c8e725b531372e1d Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Wed, 15 Nov 2023 18:22:04 -0500 Subject: [PATCH 1/2] Initialize the RuntimeScheduler and TurboModule bindings via RuntimeExecutor In order to minimize the dependency on the JSI runtime holder, this switches the initialization of TurboModules and RuntimeScheduler bindings to use the RuntimeExecutor, which hands us back the Runtime instance. --- vnext/Shared/OInstance.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/vnext/Shared/OInstance.cpp b/vnext/Shared/OInstance.cpp index a2eaa2aba22..fcf90fb8345 100644 --- a/vnext/Shared/OInstance.cpp +++ b/vnext/Shared/OInstance.cpp @@ -361,17 +361,15 @@ InstanceImpl::InstanceImpl( winrt::Microsoft::ReactNative::ReactPropertyBag(propertyBag), m_runtimeScheduler); } - // Using runOnQueueSync because initializeBridge calls createJSExecutor with runOnQueueSync, - // so this is an attempt to keep the same semantics for exiting this method with TurboModuleManager - // initialized. - m_jsThread->runOnQueueSync([propertyBag, - innerInstance = m_innerInstance, - runtimeHolder = m_devSettings->jsiRuntimeHolder, - runtimeScheduler = m_runtimeScheduler, - turboModuleRegistry = m_turboModuleRegistry, - longLivedObjectCollection = m_longLivedObjectCollection]() { + // Use RuntimeExecutor so non-ABI JSExecutorFactory instances passed in through DevSettings + // can use the same logic + runtimeExecutor([propertyBag, + innerInstance = m_innerInstance, + runtimeScheduler = m_runtimeScheduler, + turboModuleRegistry = m_turboModuleRegistry, + longLivedObjectCollection = m_longLivedObjectCollection](jsi::Runtime &runtime) { if (runtimeScheduler) { - RuntimeSchedulerBinding::createAndInstallIfNeeded(*runtimeHolder->getRuntime(), runtimeScheduler); + RuntimeSchedulerBinding::createAndInstallIfNeeded(runtime, runtimeScheduler); } auto turboModuleManager = std::make_shared( turboModuleRegistry, @@ -386,10 +384,7 @@ InstanceImpl::InstanceImpl( }; TurboModuleBinding::install( - *runtimeHolder->getRuntime(), - std::function(binding), - TurboModuleBindingMode::HostObject, - longLivedObjectCollection); + runtime, std::function(binding), TurboModuleBindingMode::HostObject, longLivedObjectCollection); // init TurboModule for (const auto &moduleName : turboModuleManager->getEagerInitModuleNames()) { From 39895bb8377d0ee6665e731ff7a2d7a46de0a47f Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Wed, 15 Nov 2023 18:25:38 -0500 Subject: [PATCH 2/2] Change files --- ...ative-windows-c86adf9d-416f-439c-aaac-f1c932b141ea.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/react-native-windows-c86adf9d-416f-439c-aaac-f1c932b141ea.json diff --git a/change/react-native-windows-c86adf9d-416f-439c-aaac-f1c932b141ea.json b/change/react-native-windows-c86adf9d-416f-439c-aaac-f1c932b141ea.json new file mode 100644 index 00000000000..cd37750c783 --- /dev/null +++ b/change/react-native-windows-c86adf9d-416f-439c-aaac-f1c932b141ea.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Initialize the RuntimeScheduler and TurboModule bindings via RuntimeExecutor", + "packageName": "react-native-windows", + "email": "erozell@outlook.com", + "dependentChangeType": "patch" +}