Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: For brownfield apps, it is possible to have multiple hermes runtimes serving different JS bundles. Hermes inspector currently only supports single JS bundle. The latest loaded JS bundle will overwrite previous JS bundle. This is because we always use the ["Hermes React Native" as the inspector page name](https://github.com/facebook/react-native/blob/de75a7a22eebbe6b7106377bdd697a2d779b91b0/ReactCommon/hermes/executor/HermesExecutorFactory.cpp#L157) and [the latest page name will overwrite previous one](https://github.com/facebook/react-native/blob/de75a7a22eebbe6b7106377bdd697a2d779b91b0/ReactCommon/hermes/inspector/chrome/ConnectionDemux.cpp#L77-L86). This PR adds more customization for HermesExecutorFactory: - `setEnableDebugger`: provide a way to disable debugging features for the hermes runtime - `setDebuggerName`: provide a way to customize inspector page name other than the default "Hermes React Native" ## Changelog [General] [Added] - Add more debugging settings for *HermesExecutorFactory* Pull Request resolved: #34489 Test Plan: Verify the features by RNTester. 1. `setEnableDebugger` ```diff --- a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java +++ b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java @@ -10,10 +10,12 @@ package com.facebook.react.uiapp; import android.app.Application; import androidx.annotation.NonNull; import com.facebook.fbreact.specs.SampleTurboModule; +import com.facebook.hermes.reactexecutor.HermesExecutorFactory; import com.facebook.react.ReactApplication; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.react.TurboReactPackage; +import com.facebook.react.bridge.JavaScriptExecutorFactory; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.config.ReactFeatureFlags; @@ -50,6 +52,13 @@ public class RNTesterApplication extends Application implements ReactApplication return BuildConfig.DEBUG; } + Override + protected JavaScriptExecutorFactory getJavaScriptExecutorFactory() { + HermesExecutorFactory factory = new HermesExecutorFactory(); + factory.setEnableDebugger(false); + return factory; + } + Override public List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( ``` after app launched, the metro inspector should return empty array. Run `curl http://localhost:8081/json` and returns `[]` 2. `setDebuggerName` ```diff --- a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java +++ b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java @@ -10,10 +10,12 @@ package com.facebook.react.uiapp; import android.app.Application; import androidx.annotation.NonNull; import com.facebook.fbreact.specs.SampleTurboModule; +import com.facebook.hermes.reactexecutor.HermesExecutorFactory; import com.facebook.react.ReactApplication; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.react.TurboReactPackage; +import com.facebook.react.bridge.JavaScriptExecutorFactory; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.config.ReactFeatureFlags; @@ -50,6 +52,13 @@ public class RNTesterApplication extends Application implements ReactApplication return BuildConfig.DEBUG; } + Override + protected JavaScriptExecutorFactory getJavaScriptExecutorFactory() { + HermesExecutorFactory factory = new HermesExecutorFactory(); + factory.setDebuggerName("Custom Hermes Debugger"); + return factory; + } + Override public List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( ``` after app launched, the metro inspector should return an entry with *Custom Hermes Debugger* Run `curl http://localhost:8081/json` and returns ```json [ { "id": "2-1", "description": "com.facebook.react.uiapp", "title": "Custom Hermes Debugger", "faviconUrl": "https://reactjs.org/favicon.ico", "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D2 (e5c5dcd9e26e9443f59864d9763b049e0bda98e7)&page=1 (ea93151)", "type": "node", "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=2&page=1", "vm": "Hermes" } ] ``` Reviewed By: mdvacca Differential Revision: D38982104 Pulled By: cipolleschi fbshipit-source-id: 78003c173db55448a751145986985b3e1d1c71bb
- Loading branch information