From 2f46a49b8d8a11d5cf4342eee83c469b545c6779 Mon Sep 17 00:00:00 2001 From: lukmccall Date: Mon, 4 Aug 2025 04:46:56 -0700 Subject: [PATCH] Fix `ReactHostImpl.nativeModules` always returning an empty list (#52986) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: During the Expo QA process, we discovered that `ReactContext.reactApplicationContext.nativeModules` always returns an empty list (https://github.com/expo/expo/blob/4e2bbb23edda74d0e24756fd1735b8763e38f7a7/packages/expo-modules-core/android/src/main/java/expo/modules/kotlin/ReactExtensions.kt#L12). This happens because, during object creation, the `reactInstance` is always null. ## Changelog: [ANDROID] [FIXED] - Fix `ReactHostImpl.nativeModules` always returning an empty list Pull Request resolved: https://github.com/facebook/react-native/pull/52986 Test Plan: - RN tester compiles ✅ Reviewed By: mdvacca Differential Revision: D79451613 Pulled By: cortinico fbshipit-source-id: d5341bcc1193eb948db4e99f16ba32a63073a6db --- .../src/main/java/com/facebook/react/runtime/ReactHostImpl.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.kt index c91f564db47..a11175a2cb9 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.kt @@ -521,7 +521,8 @@ public class ReactHostImpl( internal fun hasNativeModule(nativeModuleInterface: Class): Boolean = reactInstance?.hasNativeModule(nativeModuleInterface) ?: false - internal val nativeModules: Collection = reactInstance?.nativeModules ?: listOf() + internal val nativeModules: Collection + get() = reactInstance?.nativeModules ?: listOf() internal fun getNativeModule(nativeModuleInterface: Class): T? { if (!ReactBuildConfig.UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE &&