From d5c6b693b93f66c75729d678bb5136b431f68a6a Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Mon, 27 Jan 2025 14:15:47 +0100 Subject: [PATCH 1/2] fix(react-native): pass the protocol from bundle URL to HMR client on Android --- .../react/devsupport/DevSupportManagerBase.java | 3 ++- .../com/facebook/react/devsupport/HMRClient.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java index 8278b93d9559..63dd5fcb5c04 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java @@ -685,10 +685,11 @@ private void resetCurrentContext(@Nullable ReactContext reactContext) { URL sourceUrl = new URL(getSourceUrl()); String path = sourceUrl.getPath().substring(1); // strip initial slash in path String host = sourceUrl.getHost(); + String scheme = sourceUrl.getProtocol(); int port = sourceUrl.getPort() != -1 ? sourceUrl.getPort() : sourceUrl.getDefaultPort(); mCurrentReactContext .getJSModule(HMRClient.class) - .setup("android", path, host, port, mDevSettings.isHotModuleReplacementEnabled()); + .setup("android", path, host, port, mDevSettings.isHotModuleReplacementEnabled(), scheme); } catch (MalformedURLException e) { showNewJavaError(e.getMessage(), e); } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/HMRClient.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/HMRClient.java index 7807ef449018..38d4edb64430 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/HMRClient.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/HMRClient.java @@ -29,6 +29,18 @@ public interface HMRClient extends JavaScriptModule { */ void setup(String platform, String bundleEntry, String host, int port, boolean isEnabled); + /** + * Enable the HMRClient so that the client will receive updates from Metro. + * + * @param platform The platform in which HMR updates will be enabled. Should be "android". + * @param bundleEntry The path to the bundle entry file (e.g. index.ios.bundle). + * @param host The host that the HMRClient should communicate with. + * @param port The port that the HMRClient should communicate with on the host. + * @param isEnabled Whether HMR is enabled initially. + * @param scheme The protocol that the HMRClient should communicate with on the host (defaults to http). + */ + void setup(String platform, String bundleEntry, String host, int port, boolean isEnabled, String scheme); + /** Registers an additional JS bundle with HMRClient. */ void registerBundle(String bundleUrl); From 55902b25de0341d31a48d52d69c8672084971216 Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Tue, 28 Jan 2025 11:37:12 +0100 Subject: [PATCH 2/2] refactor(react-native): remove method overloading and add scheme to `HMRClient.setup` --- .../java/com/facebook/react/devsupport/HMRClient.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/HMRClient.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/HMRClient.java index 38d4edb64430..c4bf9992d787 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/HMRClient.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/HMRClient.java @@ -18,17 +18,6 @@ */ public interface HMRClient extends JavaScriptModule { - /** - * Enable the HMRClient so that the client will receive updates from Metro. - * - * @param platform The platform in which HMR updates will be enabled. Should be "android". - * @param bundleEntry The path to the bundle entry file (e.g. index.ios.bundle). - * @param host The host that the HMRClient should communicate with. - * @param port The port that the HMRClient should communicate with on the host. - * @param isEnabled Whether HMR is enabled initially. - */ - void setup(String platform, String bundleEntry, String host, int port, boolean isEnabled); - /** * Enable the HMRClient so that the client will receive updates from Metro. *