diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a51d4a..dc7933d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- We fixed an intermittent issue where Make it Native could fail to load the app with an "Unable to load script" error, because the Metro bundler was checked at the emulator default address (`10.0.2.2:8081`) instead of the address of the Mendix app. + ## [v1.0.0] - 2026-11-04 - We upgraded the react-native to version 0.88.0 and bumped related dependencies. diff --git a/android/src/main/java/com/mendix/mendixnative/devsupport/MendixBridgelessDevSupportManager.kt b/android/src/main/java/com/mendix/mendixnative/devsupport/MendixBridgelessDevSupportManager.kt index ac9d74c..70e3eef 100644 --- a/android/src/main/java/com/mendix/mendixnative/devsupport/MendixBridgelessDevSupportManager.kt +++ b/android/src/main/java/com/mendix/mendixnative/devsupport/MendixBridgelessDevSupportManager.kt @@ -7,9 +7,11 @@ import com.facebook.react.devsupport.DevSupportManagerBase import com.facebook.react.devsupport.ReactInstanceDevHelper import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener import com.facebook.react.devsupport.interfaces.DevLoadingViewManager +import com.facebook.react.devsupport.interfaces.PackagerStatusCallback import com.facebook.react.devsupport.interfaces.PausedInDebuggerOverlayManager import com.facebook.react.devsupport.interfaces.RedBoxHandler import com.facebook.react.packagerconnection.RequestHandler +import com.mendix.mendixnative.config.AppPreferences /** * A public DevSupportManager implementation for Mendix apps in bridgeless mode. @@ -43,8 +45,29 @@ class MendixBridgelessDevSupportManager( devLoadingViewManager, pausedInDebuggerOverlayManager, ) { + private val mxContext: Context = applicationContext + override val uniqueTag: String get() = "MendixBridgeless" + /** + * React Native's [com.facebook.react.packagerconnection.PackagerConnectionSettings] caches the + * resolved debug server host in a static field. When nothing is stored yet, a background read + * (e.g. opening the packager websocket when this manager is created) resolves the emulator + * default (10.0.2.2:8081) and writes it to that cache after we have already set the host for + * the Mendix app, overwriting it. Metro would then be reported as not running and + * [com.facebook.react.runtime.ReactHostImpl] falls back to the asset bundle, which doesn't exist + * in developer builds ("Unable to load script"). + * + * Re-apply the host Mendix stored for this app right before the check so it always wins. + */ + override fun isPackagerRunning(callback: PackagerStatusCallback) { + val storedHost = AppPreferences(mxContext).metroBundlerHost + if (storedHost.isNotEmpty()) { + devSettings.packagerConnectionSettings.debugServerHost = storedHost + } + super.isPackagerRunning(callback) + } + override fun handleReloadJS() { UiThreadUtil.assertOnUiThread() hideRedboxDialog()