mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Back out "Remove some Tasks overhead" (#46483)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46483 Original commit changeset: 631d741bd2ec This is breaking the RedBox on React Native 0.76 on Android when not connected to Metro. Original Phabricator Diff: D62213722 Changelog: [Internal] [Changed] - Back out "[react-native] Remove some Tasks overhead" Reviewed By: cipolleschi Differential Revision: D62644614 fbshipit-source-id: a092614da78bef65546c2539a3ebc9bff5e807b2
This commit is contained in:
committed by
Riccardo Cipolleschi
parent
1dd89df561
commit
c41ab475b1
+14
-9
@@ -23,6 +23,8 @@ import com.facebook.react.devsupport.HMRClient;
|
||||
import com.facebook.react.devsupport.ReactInstanceDevHelper;
|
||||
import com.facebook.react.devsupport.interfaces.DevSplitBundleCallback;
|
||||
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
||||
import com.facebook.react.runtime.internal.bolts.Continuation;
|
||||
import com.facebook.react.runtime.internal.bolts.Task;
|
||||
|
||||
/**
|
||||
* An implementation of {@link com.facebook.react.devsupport.interfaces.DevSupportManager} that
|
||||
@@ -67,17 +69,20 @@ class BridgelessDevSupportManager extends DevSupportManagerBase {
|
||||
mReactHost
|
||||
.loadBundle(bundleLoader)
|
||||
.onSuccess(
|
||||
task -> {
|
||||
if (task.isCompleted()) {
|
||||
String bundleURL =
|
||||
getDevServerHelper().getDevServerSplitBundleURL(bundlePath);
|
||||
ReactContext reactContext = mReactHost.getCurrentReactContext();
|
||||
if (reactContext != null) {
|
||||
reactContext.getJSModule(HMRClient.class).registerBundle(bundleURL);
|
||||
new Continuation<Boolean, Void>() {
|
||||
@Override
|
||||
public Void then(Task<Boolean> task) {
|
||||
if (task.getResult().equals(Boolean.TRUE)) {
|
||||
String bundleURL =
|
||||
getDevServerHelper().getDevServerSplitBundleURL(bundlePath);
|
||||
ReactContext reactContext = mReactHost.getCurrentReactContext();
|
||||
if (reactContext != null) {
|
||||
reactContext.getJSModule(HMRClient.class).registerBundle(bundleURL);
|
||||
}
|
||||
callback.onSuccess();
|
||||
}
|
||||
callback.onSuccess();
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+26
-21
@@ -9,6 +9,8 @@ package com.facebook.react.runtime;
|
||||
|
||||
import static com.facebook.infer.annotation.Assertions.assertNotNull;
|
||||
import static com.facebook.infer.annotation.ThreadConfined.UI;
|
||||
import static java.lang.Boolean.FALSE;
|
||||
import static java.lang.Boolean.TRUE;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
@@ -250,12 +252,13 @@ public class ReactHostImpl implements ReactHost {
|
||||
|
||||
detachSurface(surface);
|
||||
return callWithExistingReactInstance(
|
||||
method,
|
||||
reactInstance -> {
|
||||
log(method, "Execute");
|
||||
reactInstance.stopSurface(surface);
|
||||
},
|
||||
mBGExecutor);
|
||||
method,
|
||||
reactInstance -> {
|
||||
log(method, "Execute");
|
||||
reactInstance.stopSurface(surface);
|
||||
},
|
||||
mBGExecutor)
|
||||
.makeVoid();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -776,7 +779,7 @@ public class ReactHostImpl implements ReactHost {
|
||||
};
|
||||
}
|
||||
|
||||
/* package */ Task<Void> loadBundle(final JSBundleLoader bundleLoader) {
|
||||
/* package */ Task<Boolean> loadBundle(final JSBundleLoader bundleLoader) {
|
||||
final String method = "loadBundle()";
|
||||
log(method, "Schedule");
|
||||
|
||||
@@ -789,7 +792,7 @@ public class ReactHostImpl implements ReactHost {
|
||||
null);
|
||||
}
|
||||
|
||||
/* package */ Task<Void> registerSegment(
|
||||
/* package */ Task<Boolean> registerSegment(
|
||||
final int segmentId, final String path, final Callback callback) {
|
||||
final String method =
|
||||
"registerSegment(segmentId = \"" + segmentId + "\", path = \"" + path + "\")";
|
||||
@@ -825,7 +828,7 @@ public class ReactHostImpl implements ReactHost {
|
||||
* @param args Arguments to be passed to the function
|
||||
* @return A Task that will complete when the function call has been enqueued on the JS thread.
|
||||
*/
|
||||
/* package */ Task<Void> callFunctionOnModule(
|
||||
/* package */ Task<Boolean> callFunctionOnModule(
|
||||
final String moduleName, final String methodName, final NativeArray args) {
|
||||
final String method = "callFunctionOnModule(\"" + moduleName + "\", \"" + methodName + "\")";
|
||||
return callWithExistingReactInstance(
|
||||
@@ -947,9 +950,9 @@ public class ReactHostImpl implements ReactHost {
|
||||
}
|
||||
|
||||
/** Schedule work on a ReactInstance that is already created. */
|
||||
private Task<Void> callWithExistingReactInstance(
|
||||
private Task<Boolean> callWithExistingReactInstance(
|
||||
final String callingMethod,
|
||||
final ReactInstanceCalback callback,
|
||||
final ReactInstanceCalback continuation,
|
||||
@Nullable Executor executor) {
|
||||
final String method = "callWithExistingReactInstance(" + callingMethod + ")";
|
||||
|
||||
@@ -959,18 +962,19 @@ public class ReactHostImpl implements ReactHost {
|
||||
|
||||
return mCreateReactInstanceTaskRef
|
||||
.get()
|
||||
.continueWith(
|
||||
.onSuccess(
|
||||
task -> {
|
||||
final ReactInstance reactInstance =
|
||||
ReactNativeFeatureFlags.completeReactInstanceCreationOnBgThreadOnAndroid()
|
||||
? task.getResult()
|
||||
: mReactInstance;
|
||||
if (reactInstance == null || task.isFaulted()) {
|
||||
if (reactInstance == null) {
|
||||
raiseSoftException(method, "Execute: reactInstance is null. Dropping work.");
|
||||
} else {
|
||||
callback.then(reactInstance);
|
||||
return FALSE;
|
||||
}
|
||||
return null;
|
||||
|
||||
continuation.then(reactInstance);
|
||||
return TRUE;
|
||||
},
|
||||
executor);
|
||||
}
|
||||
@@ -978,7 +982,7 @@ public class ReactHostImpl implements ReactHost {
|
||||
/** Create a ReactInstance if it doesn't exist already, and schedule work on it. */
|
||||
private Task<Void> callAfterGetOrCreateReactInstance(
|
||||
final String callingMethod,
|
||||
final ReactInstanceCalback callback,
|
||||
final ReactInstanceCalback runnable,
|
||||
@Nullable Executor executor) {
|
||||
final String method = "callAfterGetOrCreateReactInstance(" + callingMethod + ")";
|
||||
|
||||
@@ -987,17 +991,18 @@ public class ReactHostImpl implements ReactHost {
|
||||
}
|
||||
|
||||
return getOrCreateReactInstance()
|
||||
.continueWith(
|
||||
.onSuccess(
|
||||
task -> {
|
||||
final ReactInstance reactInstance =
|
||||
ReactNativeFeatureFlags.completeReactInstanceCreationOnBgThreadOnAndroid()
|
||||
? task.getResult()
|
||||
: mReactInstance;
|
||||
if (reactInstance == null || task.isFaulted()) {
|
||||
if (reactInstance == null) {
|
||||
raiseSoftException(method, "Execute: reactInstance is null. Dropping work.");
|
||||
} else {
|
||||
callback.then(reactInstance);
|
||||
return null;
|
||||
}
|
||||
|
||||
runnable.then(reactInstance);
|
||||
return null;
|
||||
},
|
||||
executor)
|
||||
|
||||
Reference in New Issue
Block a user