Skip to content

Commit

Permalink
et update-rn
Browse files Browse the repository at this point in the history
do not pick this commit - instead run `et update-rn` from expo repo root
  • Loading branch information
vonovak committed Feb 25, 2025
1 parent 6a04d91 commit d834557
Show file tree
Hide file tree
Showing 11 changed files with 2,694 additions and 3,250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.bridge;

/** Crashy crashy exception handler. */
public class DefaultJSExceptionHandler implements JSExceptionHandler {

@Override
public void handleException(Exception e) {
if (e instanceof RuntimeException) {
// Because we are rethrowing the original exception, the original stacktrace will be
// preserved.
throw (RuntimeException) e;
} else {
throw new RuntimeException(e);
@Override
public void handleException(Exception e) {
try {
{
if (e instanceof RuntimeException) {
// preserved.
throw (RuntimeException) e;
} else {
throw new RuntimeException(e);
}
}
} catch (RuntimeException expoException) {
try {
Class.forName("host.exp.exponent.ReactNativeStaticHelpers").getMethod("handleReactNativeError", String.class, Object.class, Integer.class, Boolean.class).invoke(null, expoException.getMessage(), null, -1, true);
} catch (Exception expoHandleErrorException) {
expoHandleErrorException.printStackTrace();
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.devsupport;

import android.content.Context;
Expand Down Expand Up @@ -55,138 +54,94 @@
* is responsible for enabling/disabling dev support in case when app is backgrounded or when all
* the views has been detached from the instance (through {@link #setDevSupportEnabled} method).
*/
public final class BridgeDevSupportManager extends DevSupportManagerBase {
private boolean mIsSamplingProfilerEnabled = false;

public BridgeDevSupportManager(
Context applicationContext,
ReactInstanceDevHelper reactInstanceManagerHelper,
@Nullable String packagerPathForJSBundleName,
boolean enableOnCreate,
@Nullable RedBoxHandler redBoxHandler,
@Nullable DevBundleDownloadListener devBundleDownloadListener,
int minNumShakes,
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers,
@Nullable SurfaceDelegateFactory surfaceDelegateFactory,
@Nullable DevLoadingViewManager devLoadingViewManager,
@Nullable PausedInDebuggerOverlayManager pausedInDebuggerOverlayManager) {
super(
applicationContext,
reactInstanceManagerHelper,
packagerPathForJSBundleName,
enableOnCreate,
redBoxHandler,
devBundleDownloadListener,
minNumShakes,
customPackagerCommandHandlers,
surfaceDelegateFactory,
devLoadingViewManager,
pausedInDebuggerOverlayManager);
}

@Override
protected String getUniqueTag() {
return "Bridge";
}
public class BridgeDevSupportManager extends DevSupportManagerBase {

@Override
public void loadSplitBundleFromServer(
final String bundlePath, final DevSplitBundleCallback callback) {
fetchSplitBundleAndCreateBundleLoader(
bundlePath,
new CallbackWithBundleLoader() {
@Override
public void onSuccess(JSBundleLoader bundleLoader) {
bundleLoader.loadScript(getCurrentReactContext().getCatalystInstance());
getCurrentReactContext()
.getJSModule(HMRClient.class)
.registerBundle(getDevServerHelper().getDevServerSplitBundleURL(bundlePath));
callback.onSuccess();
}
public boolean mIsSamplingProfilerEnabled = false;

@Override
public void onError(String url, Throwable cause) {
callback.onError(url, cause);
}
});
}
public BridgeDevSupportManager(Context applicationContext, ReactInstanceDevHelper reactInstanceManagerHelper, @Nullable String packagerPathForJSBundleName, boolean enableOnCreate, @Nullable RedBoxHandler redBoxHandler, @Nullable DevBundleDownloadListener devBundleDownloadListener, int minNumShakes, @Nullable Map<String, RequestHandler> customPackagerCommandHandlers, @Nullable SurfaceDelegateFactory surfaceDelegateFactory, @Nullable DevLoadingViewManager devLoadingViewManager, @Nullable PausedInDebuggerOverlayManager pausedInDebuggerOverlayManager) {
super(applicationContext, reactInstanceManagerHelper, packagerPathForJSBundleName, enableOnCreate, redBoxHandler, devBundleDownloadListener, minNumShakes, customPackagerCommandHandlers, surfaceDelegateFactory, devLoadingViewManager, pausedInDebuggerOverlayManager);
}

private WebsocketJavaScriptExecutor.JSExecutorConnectCallback getExecutorConnectCallback(
final SimpleSettableFuture<Boolean> future) {
return new WebsocketJavaScriptExecutor.JSExecutorConnectCallback() {
@Override
public void onSuccess() {
future.set(true);
hideDevLoadingView();
}
@Override
protected String getUniqueTag() {
return "Bridge";
}

@Override
public void onFailure(final Throwable cause) {
hideDevLoadingView();
FLog.e(ReactConstants.TAG, "Failed to connect to debugger!", cause);
future.setException(
new IOException(
getApplicationContext().getString(com.facebook.react.R.string.catalyst_debug_error),
cause));
}
};
}
@Override
public void loadSplitBundleFromServer(final String bundlePath, final DevSplitBundleCallback callback) {
fetchSplitBundleAndCreateBundleLoader(bundlePath, new CallbackWithBundleLoader() {

private void reloadJSInProxyMode() {
// When using js proxy, there is no need to fetch JS bundle as proxy executor will do that
// anyway
getDevServerHelper().launchJSDevtools();
@Override
public void onSuccess(JSBundleLoader bundleLoader) {
bundleLoader.loadScript(getCurrentReactContext().getCatalystInstance());
getCurrentReactContext().getJSModule(HMRClient.class).registerBundle(getDevServerHelper().getDevServerSplitBundleURL(bundlePath));
callback.onSuccess();
}

JavaJSExecutor.Factory factory =
new JavaJSExecutor.Factory() {
@Override
public JavaJSExecutor create() throws Exception {
WebsocketJavaScriptExecutor executor = new WebsocketJavaScriptExecutor();
SimpleSettableFuture<Boolean> future = new SimpleSettableFuture<>();
executor.connect(
getDevServerHelper().getWebsocketProxyURL(), getExecutorConnectCallback(future));
// TODO(t9349129) Don't use timeout
try {
future.get(90, TimeUnit.SECONDS);
return executor;
} catch (ExecutionException e) {
throw (Exception) e.getCause();
} catch (InterruptedException | TimeoutException e) {
throw new RuntimeException(e);
@Override
public void onError(String url, Throwable cause) {
callback.onError(url, cause);
}
}
};
getReactInstanceDevHelper().onReloadWithJSDebugger(factory);
}
});
}

@Override
public void handleReloadJS() {
private WebsocketJavaScriptExecutor.JSExecutorConnectCallback getExecutorConnectCallback(final SimpleSettableFuture<Boolean> future) {
return new WebsocketJavaScriptExecutor.JSExecutorConnectCallback() {

UiThreadUtil.assertOnUiThread();
@Override
public void onSuccess() {
future.set(true);
hideDevLoadingView();
}

ReactMarker.logMarker(
ReactMarkerConstants.RELOAD,
getDevSettings().getPackagerConnectionSettings().getDebugServerHost());
@Override
public void onFailure(final Throwable cause) {
hideDevLoadingView();
FLog.e(ReactConstants.TAG, "Failed to connect to debugger!", cause);
future.setException(new IOException(getApplicationContext().getString(com.facebook.react.R.string.catalyst_debug_error), cause));
}
};
}

// dismiss redbox if exists
hideRedboxDialog();
private void reloadJSInProxyMode() {
// When using js proxy, there is no need to fetch JS bundle as proxy executor will do that
// anyway
getDevServerHelper().launchJSDevtools();
JavaJSExecutor.Factory factory = new JavaJSExecutor.Factory() {

@Override
public JavaJSExecutor create() throws Exception {
WebsocketJavaScriptExecutor executor = new WebsocketJavaScriptExecutor();
SimpleSettableFuture<Boolean> future = new SimpleSettableFuture<>();
executor.connect(getDevServerHelper().getWebsocketProxyURL(), getExecutorConnectCallback(future));
// TODO(t9349129) Don't use timeout
try {
future.get(90, TimeUnit.SECONDS);
return executor;
} catch (ExecutionException e) {
throw (Exception) e.getCause();
} catch (InterruptedException | TimeoutException e) {
throw new RuntimeException(e);
}
}
};
getReactInstanceDevHelper().onReloadWithJSDebugger(factory);
}

if (getDevSettings().isRemoteJSDebugEnabled()) {
PrinterHolder.getPrinter()
.logMessage(ReactDebugOverlayTags.RN_CORE, "RNCore: load from Proxy");
showDevLoadingViewForRemoteJSEnabled();
reloadJSInProxyMode();
} else {
PrinterHolder.getPrinter()
.logMessage(ReactDebugOverlayTags.RN_CORE, "RNCore: load from Server");
String bundleURL =
getDevServerHelper()
.getDevServerBundleURL(Assertions.assertNotNull(getJSAppBundleName()));
reloadJSFromServer(
bundleURL,
() ->
UiThreadUtil.runOnUiThread(
() -> getReactInstanceDevHelper().onJSBundleLoadedFromServer()));
@Override
public void handleReloadJS() {
UiThreadUtil.assertOnUiThread();
ReactMarker.logMarker(ReactMarkerConstants.RELOAD, getDevSettings().getPackagerConnectionSettings().getDebugServerHost());
// dismiss redbox if exists
hideRedboxDialog();
if (getDevSettings().isRemoteJSDebugEnabled()) {
PrinterHolder.getPrinter().logMessage(ReactDebugOverlayTags.RN_CORE, "RNCore: load from Proxy");
showDevLoadingViewForRemoteJSEnabled();
reloadJSInProxyMode();
} else {
PrinterHolder.getPrinter().logMessage(ReactDebugOverlayTags.RN_CORE, "RNCore: load from Server");
String bundleURL = getDevServerHelper().getDevServerBundleURL(Assertions.assertNotNull(getJSAppBundleName()));
reloadJSFromServer(bundleURL, () -> UiThreadUtil.runOnUiThread(() -> getReactInstanceDevHelper().onJSBundleLoadedFromServer()));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* APIs for asynchronously loading the JS bundle.
*/
@Nullsafe(Nullsafe.Mode.LOCAL)
class BridgelessDevSupportManager extends DevSupportManagerBase {
public class BridgelessDevSupportManager extends DevSupportManagerBase {

public BridgelessDevSupportManager(
Context context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.facebook.react.packagerconnection.PackagerConnectionSettings
* [com.facebook.react.devsupport]. For accessing some of the settings by external modules this
* class implements an external interface [DeveloperSettings].
*/
internal class DevInternalSettings(applicationContext: Context, private val listener: Listener?) :
public class DevInternalSettings(applicationContext: Context, private val listener: Listener?) :
DeveloperSettings, OnSharedPreferenceChangeListener {
private val preferences: SharedPreferences =
PreferenceManager.getDefaultSharedPreferences(applicationContext)
Expand Down Expand Up @@ -86,19 +86,19 @@ internal class DevInternalSettings(applicationContext: Context, private val list
override var isStartSamplingProfilerOnInit: Boolean = false

// Not supported.
override fun addMenuItem(title: String) = Unit
override fun addMenuItem(title: String): Unit = Unit

override var isHotModuleReplacementEnabled: Boolean
get() = preferences.getBoolean(PREFS_HOT_MODULE_REPLACEMENT_KEY, true)
set(enabled) {
preferences.edit().putBoolean(PREFS_HOT_MODULE_REPLACEMENT_KEY, enabled).apply()
}

interface Listener {
fun onInternalSettingsChanged()
public interface Listener {
public fun onInternalSettingsChanged()
}

companion object {
public companion object {
private const val PREFS_FPS_DEBUG_KEY = "fps_debug"
private const val PREFS_JS_DEV_MODE_DEBUG_KEY = "js_dev_mode_debug"
private const val PREFS_JS_MINIFY_DEBUG_KEY = "js_minify_debug"
Expand All @@ -107,4 +107,15 @@ internal class DevInternalSettings(applicationContext: Context, private val list
private const val PREFS_HOT_MODULE_REPLACEMENT_KEY = "hot_module_replacement"
private const val PREFS_REMOTE_JS_DEBUG_KEY = "remote_js_debug"
}

private var exponentActivityId: Int = -1

public fun setExponentActivityId(value: Int) {
exponentActivityId = value
}

public override fun getExponentActivityId(): Int {
return exponentActivityId
}

}
Loading

0 comments on commit d834557

Please sign in to comment.