Skip to content

Commit 7af288e

Browse files
motiz88facebook-github-bot
authored andcommitted
Lazy-init HermesRuntimeTargetDelegate
Summary: Changelog: [Internal] We are currently eagerly constructing a `HermesRuntimeTargetDelegate` regardless of whether the Fusebox feature flags are enabled. This can interfere with the legacy CDP backend. Instead, let's lazily construct the target delegate in a code path that only runs when the modern backend is in use. bypass-github-export-checks Reviewed By: rozele Differential Revision: D54907887 fbshipit-source-id: 7dc13506739866ea6690ed21d03d91ad24ef68c5
1 parent a2d277f commit 7af288e

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,14 @@ HermesExecutor::HermesExecutor(
253253
HermesRuntime& hermesRuntime)
254254
: JSIExecutor(runtime, delegate, timeoutInvoker, runtimeInstaller),
255255
runtime_(runtime),
256-
targetDelegate_{
257-
std::shared_ptr<HermesRuntime>(runtime_, &hermesRuntime)} {}
256+
hermesRuntime_(runtime_, &hermesRuntime) {}
258257

259258
jsinspector_modern::RuntimeTargetDelegate&
260259
HermesExecutor::getRuntimeTargetDelegate() {
261-
return targetDelegate_;
260+
if (!targetDelegate_) {
261+
targetDelegate_.emplace(hermesRuntime_);
262+
}
263+
return *targetDelegate_;
262264
}
263265

264266
} // namespace facebook::react

packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ class HermesExecutor : public JSIExecutor {
6161
private:
6262
JSIScopedTimeoutInvoker timeoutInvoker_;
6363
std::shared_ptr<jsi::Runtime> runtime_;
64-
jsinspector_modern::HermesRuntimeTargetDelegate targetDelegate_;
64+
std::shared_ptr<hermes::HermesRuntime> hermesRuntime_;
65+
std::optional<jsinspector_modern::HermesRuntimeTargetDelegate>
66+
targetDelegate_;
6567
};
6668

6769
} // namespace facebook::react

packages/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,24 @@ class DecoratedRuntime : public jsi::RuntimeDecorator<jsi::Runtime> {
9595
class HermesJSRuntime : public JSRuntime {
9696
public:
9797
HermesJSRuntime(std::unique_ptr<HermesRuntime> runtime)
98-
: runtime_(std::move(runtime)), targetDelegate_{runtime_} {}
98+
: runtime_(std::move(runtime)) {}
9999

100100
jsi::Runtime& getRuntime() noexcept override {
101101
return *runtime_;
102102
}
103103

104104
jsinspector_modern::RuntimeTargetDelegate& getRuntimeTargetDelegate()
105105
override {
106-
return targetDelegate_;
106+
if (!targetDelegate_) {
107+
targetDelegate_.emplace(runtime_);
108+
}
109+
return *targetDelegate_;
107110
}
108111

109112
private:
110113
std::shared_ptr<HermesRuntime> runtime_;
111-
jsinspector_modern::HermesRuntimeTargetDelegate targetDelegate_;
114+
std::optional<jsinspector_modern::HermesRuntimeTargetDelegate>
115+
targetDelegate_;
112116
};
113117

114118
std::unique_ptr<JSRuntime> HermesInstance::createJSRuntime(

0 commit comments

Comments
 (0)