Skip to content

Commit 4fd4657

Browse files
authored
Revert "Undo a rearchitecture that breaks us downstream (#777)" (#793)
This reverts commit 73224cf, which itself was a revert of a commit. So we're bringing back the original change. We thought it would break things downstream for us, but are electing to instead fix things downstream rather than undo this commit.
1 parent f024031 commit 4fd4657

16 files changed

Lines changed: 416 additions & 281 deletions

File tree

RNTester/Podfile.lock

Lines changed: 335 additions & 233 deletions
Large diffs are not rendered by default.

React/CxxBridge/RCTCxxBridge.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ - (void)executeApplicationScript:(NSData *)script url:(NSURL *)url async:(BOOL)a
13701370
} else if (reactInstance) {
13711371
reactInstance->loadScriptFromString(std::make_unique<NSDataBigString>(script), sourceUrlStr.UTF8String, !async);
13721372
} else {
1373-
std::string methodName = async ? "loadApplicationScript" : "loadApplicationScriptSync";
1373+
std::string methodName = async ? "loadBundle" : "loadBundleSync";
13741374
throw std::logic_error("Attempt to call " + methodName + ": on uninitialized bridge");
13751375
}
13761376
}];

React/CxxBridge/RCTObjcExecutor.mm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@
6767
setGlobalVariable("__fbBatchedBridgeConfig", std::make_unique<JSBigStdString>(folly::toJson(config)));
6868
}
6969

70-
void loadApplicationScript(std::unique_ptr<const JSBigString> script, std::string sourceURL) override
70+
void initializeRuntime() override
71+
{
72+
// We do nothing here since initialization is done in the constructor
73+
}
74+
75+
void loadBundle(std::unique_ptr<const JSBigString> script, std::string sourceURL) override
7176
{
7277
RCTProfileBeginFlowEvent();
7378
[m_jse executeApplicationScript:[NSData dataWithBytes:script->c_str() length:script->size()]

ReactAndroid/src/main/java/com/facebook/react/bridge/JavaJSExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public ProxyExecutorException(Throwable cause) {
3838
* @param sourceURL url or file location from which script content was loaded
3939
*/
4040
@DoNotStrip
41-
void loadApplicationScript(String sourceURL) throws ProxyExecutorException;
41+
void loadBundle(String sourceURL) throws ProxyExecutorException;
4242

4343
/**
4444
* Execute javascript method within js context

ReactAndroid/src/main/java/com/facebook/react/devsupport/JSDebuggerWebSocketClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void prepareJSRuntime(JSDebuggerCallback callback) {
8181
}
8282
}
8383

84-
public void loadApplicationScript(
84+
public void loadBundle(
8585
String sourceURL, HashMap<String, String> injectedObjects, JSDebuggerCallback callback) {
8686
int requestID = mRequestID.getAndIncrement();
8787
mCallbacks.put(requestID, callback);

ReactAndroid/src/main/java/com/facebook/react/devsupport/WebsocketJavaScriptExecutor.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,9 @@ public void close() {
153153
}
154154

155155
@Override
156-
public void loadApplicationScript(String sourceURL) throws JavaJSExecutor.ProxyExecutorException {
156+
public void loadBundle(String sourceURL) throws JavaJSExecutor.ProxyExecutorException {
157157
JSExecutorCallbackFuture callback = new JSExecutorCallbackFuture();
158-
Assertions.assertNotNull(mWebSocketClient)
159-
.loadApplicationScript(sourceURL, mInjectedObjects, callback);
158+
Assertions.assertNotNull(mWebSocketClient).loadBundle(sourceURL, mInjectedObjects, callback);
160159
try {
161160
callback.get();
162161
} catch (Throwable cause) {
@@ -178,7 +177,7 @@ public void loadApplicationScript(String sourceURL) throws JavaJSExecutor.ProxyE
178177

179178
@Override
180179
public void setGlobalVariable(String propertyName, String jsonEncodedValue) {
181-
// Store and use in the next loadApplicationScript() call.
180+
// Store and use in the next loadBundle() call.
182181
mInjectedObjects.put(propertyName, jsonEncodedValue);
183182
}
184183
}

ReactAndroid/src/main/jni/react/jni/ProxyExecutor.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ ProxyExecutor::~ProxyExecutor() {
5353
m_executor.reset();
5454
}
5555

56-
void ProxyExecutor::loadApplicationScript(
57-
std::unique_ptr<const JSBigString>,
58-
std::string sourceURL) {
56+
void ProxyExecutor::initializeRuntime() {
5957
folly::dynamic nativeModuleConfig = folly::dynamic::array;
6058

6159
{
@@ -76,14 +74,17 @@ void ProxyExecutor::loadApplicationScript(
7674
"__fbBatchedBridgeConfig",
7775
std::make_unique<JSBigStdString>(folly::toJson(config)));
7876
}
77+
}
7978

80-
static auto loadApplicationScript =
81-
jni::findClassStatic(EXECUTOR_BASECLASS)
82-
->getMethod<void(jstring)>("loadApplicationScript");
79+
void ProxyExecutor::loadBundle(
80+
std::unique_ptr<const JSBigString>,
81+
std::string sourceURL) {
82+
static auto loadBundle = jni::findClassStatic(EXECUTOR_BASECLASS)
83+
->getMethod<void(jstring)>("loadBundle");
8384

8485
// The proxy ignores the script data passed in.
8586

86-
loadApplicationScript(m_executor.get(), jni::make_jstring(sourceURL).get());
87+
loadBundle(m_executor.get(), jni::make_jstring(sourceURL).get());
8788
// We can get pending calls here to native but the queue will be drained when
8889
// we launch the application.
8990
}

ReactAndroid/src/main/jni/react/jni/ProxyExecutor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class ProxyExecutor : public JSExecutor {
3737
jni::global_ref<jobject> &&executorInstance,
3838
std::shared_ptr<ExecutorDelegate> delegate);
3939
virtual ~ProxyExecutor() override;
40-
virtual void loadApplicationScript(
40+
virtual void initializeRuntime() override;
41+
virtual void loadBundle(
4142
std::unique_ptr<const JSBigString> script,
4243
std::string sourceURL) override;
4344
virtual void setBundleRegistry(

ReactAndroid/src/test/java/com/facebook/react/devsupport/JSDebuggerWebSocketClientTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void test_prepareJSRuntime_ShouldSendCorrectMessage() throws Exception {
4040
}
4141

4242
@Test
43-
public void test_loadApplicationScript_ShouldSendCorrectMessage() throws Exception {
43+
public void test_loadBundle_ShouldSendCorrectMessage() throws Exception {
4444
final JSDebuggerWebSocketClient.JSDebuggerCallback cb =
4545
PowerMockito.mock(JSDebuggerWebSocketClient.JSDebuggerCallback.class);
4646

@@ -49,7 +49,7 @@ public void test_loadApplicationScript_ShouldSendCorrectMessage() throws Excepti
4949
injectedObjects.put("key1", "value1");
5050
injectedObjects.put("key2", "value2");
5151

52-
client.loadApplicationScript("http://localhost:8080/index.js", injectedObjects, cb);
52+
client.loadBundle("http://localhost:8080/index.js", injectedObjects, cb);
5353
PowerMockito.verifyPrivate(client)
5454
.invoke(
5555
"sendMessage",

ReactCommon/cxxreact/Instance.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ void Instance::initializeBridge(
5050
nativeToJsBridge_ = std::make_shared<NativeToJsBridge>(
5151
jsef.get(), moduleRegistry_, jsQueue, callback_);
5252

53+
nativeToJsBridge_->initializeRuntime();
54+
5355
/**
5456
* After NativeToJsBridge is created, the jsi::Runtime should exist.
5557
* Also, the JS message queue thread exists. So, it's safe to
@@ -65,33 +67,33 @@ void Instance::initializeBridge(
6567
CHECK(nativeToJsBridge_);
6668
}
6769

68-
void Instance::loadApplication(
70+
void Instance::loadBundle(
6971
std::unique_ptr<RAMBundleRegistry> bundleRegistry,
7072
std::unique_ptr<const JSBigString> string,
7173
std::string sourceURL) {
7274
callback_->incrementPendingJSCalls();
73-
SystraceSection s("Instance::loadApplication", "sourceURL", sourceURL);
74-
nativeToJsBridge_->loadApplication(
75+
SystraceSection s("Instance::loadBundle", "sourceURL", sourceURL);
76+
nativeToJsBridge_->loadBundle(
7577
std::move(bundleRegistry), std::move(string), std::move(sourceURL));
7678
}
7779

78-
void Instance::loadApplicationSync(
80+
void Instance::loadBundleSync(
7981
std::unique_ptr<RAMBundleRegistry> bundleRegistry,
8082
std::unique_ptr<const JSBigString> string,
8183
std::string sourceURL) {
8284
std::unique_lock<std::mutex> lock(m_syncMutex);
8385
m_syncCV.wait(lock, [this] { return m_syncReady; });
8486

85-
SystraceSection s("Instance::loadApplicationSync", "sourceURL", sourceURL);
86-
nativeToJsBridge_->loadApplicationSync(
87+
SystraceSection s("Instance::loadBundleSync", "sourceURL", sourceURL);
88+
nativeToJsBridge_->loadBundleSync(
8789
std::move(bundleRegistry), std::move(string), std::move(sourceURL));
8890
}
8991

9092
void Instance::setSourceURL(std::string sourceURL) {
9193
callback_->incrementPendingJSCalls();
9294
SystraceSection s("Instance::setSourceURL", "sourceURL", sourceURL);
9395

94-
nativeToJsBridge_->loadApplication(nullptr, nullptr, std::move(sourceURL));
96+
nativeToJsBridge_->loadBundle(nullptr, nullptr, std::move(sourceURL));
9597
}
9698

9799
void Instance::loadScriptFromString(
@@ -100,9 +102,9 @@ void Instance::loadScriptFromString(
100102
bool loadSynchronously) {
101103
SystraceSection s("Instance::loadScriptFromString", "sourceURL", sourceURL);
102104
if (loadSynchronously) {
103-
loadApplicationSync(nullptr, std::move(string), std::move(sourceURL));
105+
loadBundleSync(nullptr, std::move(string), std::move(sourceURL));
104106
} else {
105-
loadApplication(nullptr, std::move(string), std::move(sourceURL));
107+
loadBundle(nullptr, std::move(string), std::move(sourceURL));
106108
}
107109
}
108110

@@ -158,12 +160,12 @@ void Instance::loadRAMBundle(
158160
std::string startupScriptSourceURL,
159161
bool loadSynchronously) {
160162
if (loadSynchronously) {
161-
loadApplicationSync(
163+
loadBundleSync(
162164
std::move(bundleRegistry),
163165
std::move(startupScript),
164166
std::move(startupScriptSourceURL));
165167
} else {
166-
loadApplication(
168+
loadBundle(
167169
std::move(bundleRegistry),
168170
std::move(startupScript),
169171
std::move(startupScriptSourceURL));

0 commit comments

Comments
 (0)