Skip to content

Commit a0a77f7

Browse files
Make it explicit to specify HttpClientFactoryKey and WebSocketClientFactoryKey values (#52715)
Summary: Pull Request resolved: #52715 Changelog: [Internal] Right now we rely on compile / link time magic to detect the implementation of ``` WebSocketClientFactory getWebSocketClientFactory(); HttpClientFactory getHttpClientFactory(); ``` this actually works until it does not work anymore, see .e.g.: ``` ld.lld: error: undefined symbol: facebook::react::getHttpClientFactory() >>> referenced by ReactHost.cpp:111 (xplat/js/react-native-github/packages/react-native/ReactCxxPlatform/react/runtime/ReactHost.cpp:111) >>> xplat/js/react-native-github/packages/react-native/ReactCxxPlatform/react/runtime/__runtimeAndroid__/__objects__/ReactHost.cpp.pic.o:(facebook::react::ReactHost::ReactHost(facebook::react::ReactInstanceConfig, std::__ndk1::shared_ptr<facebook::react::IMountingManager>, std::__ndk1::shared_ptr<facebook::react::RunLoopObserverManager>, std::__ndk1::shared_ptr<facebook::react::ContextContainer const>, std::__ndk1::function<void (facebook::jsi::Runtime&, facebook::react::JsErrorHandler::ProcessedError const&)>, std::__ndk1::function<void (std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, unsigned int)>, std::__ndk1::shared_ptr<facebook::react::IDevUIDelegate>, std::__ndk1::vector<std::__ndk1::function<std::__ndk1::shared_ptr<facebook::react::TurboModule> (std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::shared_ptr<facebook::react::CallInvoker> const&)>, std::__ndk1::allocator<std::__ndk1::function<std::__ndk1::shared_ptr<facebook::react::TurboModule> (std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::shared_ptr<facebook::react::CallInvoker> const&)>>>, std::__ndk1::shared_ptr<facebook::react::SurfaceDelegate>, std::__ndk1::shared_ptr<facebook::react::NativeAnimatedNodesManagerProvider>, std::__ndk1::function<void (facebook::jsi::Runtime&)>)) ld.lld: error: undefined symbol: facebook::react::getWebSocketClientFactory() >>> referenced by ReactHost.cpp:117 (xplat/js/react-native-github/packages/react-native/ReactCxxPlatform/react/runtime/ReactHost.cpp:117) >>> xplat/js/react-native-github/packages/react-native/ReactCxxPlatform/react/runtime/__runtimeAndroid__/__objects__/ReactHost.cpp.pic.o:(facebook::react::ReactHost::ReactHost(facebook::react::ReactInstanceConfig, std::__ndk1::shared_ptr<facebook::react::IMountingManager>, std::__ndk1::shared_ptr<facebook::react::RunLoopObserverManager>, std::__ndk1::shared_ptr<facebook::react::ContextContainer const>, std::__ndk1::function<void (facebook::jsi::Runtime&, facebook::react::JsErrorHandler::ProcessedError const&)>, std::__ndk1::function<void (std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, unsigned int)>, std::__ndk1::shared_ptr<facebook::react::IDevUIDelegate>, std::__ndk1::vector<std::__ndk1::function<std::__ndk1::shared_ptr<facebook::react::TurboModule> (std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::shared_ptr<facebook::react::CallInvoker> const&)>, std::__ndk1::allocator<std::__ndk1::function<std::__ndk1::shared_ptr<facebook::react::TurboModule> (std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::shared_ptr<facebook::react::CallInvoker> const&)>>>, std::__ndk1::shared_ptr<facebook::react::SurfaceDelegate>, std::__ndk1::shared_ptr<facebook::react::NativeAnimatedNodesManagerProvider>, std::__ndk1::function<void (facebook::jsi::Runtime&)>)) clang: error: linker command failed with exit code 1 (use -v to see invocation) ``` The change here makes it explicit and mandatory to set the specific implementations of these interfaces Reviewed By: lenaic Differential Revision: D78529932 fbshipit-source-id: f26876683433a58e078d6720f169702c563ed92b
1 parent 794df48 commit a0a77f7

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

packages/react-native/ReactCxxPlatform/react/http/IWebSocketClient.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <functional>
1111
#include <memory>
1212
#include <string>
13-
#include <utility>
1413

1514
namespace facebook::react {
1615

packages/react-native/ReactCxxPlatform/react/runtime/ReactHost.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ ReactHost::ReactHost(
7979
std::shared_ptr<SurfaceDelegate> logBoxSurfaceDelegate,
8080
std::shared_ptr<NativeAnimatedNodesManagerProvider>
8181
animatedNodesManagerProvider,
82-
ReactInstance::BindingsInstallFunc bindingsInstallFunc) noexcept
82+
ReactInstance::BindingsInstallFunc bindingsInstallFunc)
8383
: reactInstanceConfig_(std::move(reactInstanceConfig)) {
8484
auto componentRegistryFactory =
8585
mountingManager->getComponentRegistryFactory();
@@ -107,14 +107,12 @@ ReactHost::ReactHost(
107107
if (!reactInstanceData_->contextContainer
108108
->find<HttpClientFactory>(HttpClientFactoryKey)
109109
.has_value()) {
110-
reactInstanceData_->contextContainer->insert(
111-
HttpClientFactoryKey, getHttpClientFactory());
110+
throw std::runtime_error("No HttpClientFactory provided");
112111
}
113112
if (!reactInstanceData_->contextContainer
114113
->find<WebSocketClientFactory>(WebSocketClientFactoryKey)
115114
.has_value()) {
116-
reactInstanceData_->contextContainer->insert(
117-
WebSocketClientFactoryKey, getWebSocketClientFactory());
115+
throw std::runtime_error("No WebSocketClientFactory provided");
118116
}
119117
createReactInstance();
120118
}

packages/react-native/ReactCxxPlatform/react/runtime/ReactHost.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ class ReactHost {
5252
std::shared_ptr<SurfaceDelegate> logBoxSurfaceDelegate = nullptr,
5353
std::shared_ptr<NativeAnimatedNodesManagerProvider>
5454
animatedNodesManagerProvider = nullptr,
55-
ReactInstance::BindingsInstallFunc bindingsInstallFunc =
56-
nullptr) noexcept;
55+
ReactInstance::BindingsInstallFunc bindingsInstallFunc = nullptr);
5756
ReactHost(const ReactHost&) = delete;
5857
ReactHost& operator=(const ReactHost&) = delete;
5958
ReactHost(ReactHost&&) noexcept = delete;

private/react-native-fantom/tester/src/TesterAppDelegate.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
*/
77

88
#include "TesterAppDelegate.h"
9+
#include "NativeFantom.h"
910
#include "platform/TesterTurboModuleManagerDelegate.h"
11+
#include "stubs/StubClock.h"
12+
#include "stubs/StubHttpClient.h"
13+
#include "stubs/StubQueue.h"
14+
#include "stubs/StubWebSocketClient.h"
1015

1116
#include <folly/dynamic.h>
1217
#include <folly/json.h>
@@ -26,10 +31,6 @@
2631
#include <iostream>
2732
#include <vector>
2833

29-
#include "NativeFantom.h"
30-
#include "stubs/StubClock.h"
31-
#include "stubs/StubQueue.h"
32-
3334
namespace facebook::react {
3435

3536
namespace {
@@ -75,6 +76,9 @@ TesterAppDelegate::TesterAppDelegate(
7576
queue_ = queue;
7677
return queue;
7778
}));
79+
contextContainer->insert(HttpClientFactoryKey, getHttpClientFactory());
80+
contextContainer->insert(
81+
WebSocketClientFactoryKey, getWebSocketClientFactory());
7882

7983
runLoopObserverManager_ = std::make_shared<RunLoopObserverManager>();
8084

0 commit comments

Comments
 (0)