From f3fee67c547ace5e08bc9e119bcb80e0f3454d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Pasi=C5=84ski?= Date: Fri, 13 Sep 2024 07:58:19 -0700 Subject: [PATCH] fix: AppRegistry not callable from Native in bridgeless (#46480) Summary: AppRegistry was not treated as a Callable Module in bridgeless mode. This is breaking headless tasks on Android. Fixes: - https://github.com/facebook/react-native/issues/46050 ## Changelog: [ANDROID] [FIXED] - Made AppRegistry callable from Native code in Bridgeless (fixes headless tasks) Pull Request resolved: https://github.com/facebook/react-native/pull/46480 Test Plan: Used repro from linked issue Reviewed By: javache Differential Revision: D62637486 Pulled By: cortinico fbshipit-source-id: 756527003ac6d712e76c02c188e280d15c010068 --- .../Libraries/ReactNative/AppRegistry.js | 6 +++--- .../com/facebook/react/HeadlessJsTaskService.java | 12 ++++-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/react-native/Libraries/ReactNative/AppRegistry.js b/packages/react-native/Libraries/ReactNative/AppRegistry.js index d073995be8c859..9448296efcdb56 100644 --- a/packages/react-native/Libraries/ReactNative/AppRegistry.js +++ b/packages/react-native/Libraries/ReactNative/AppRegistry.js @@ -13,7 +13,7 @@ import type {RootTag} from '../Types/RootTagTypes'; import type {IPerformanceLogger} from '../Utilities/createPerformanceLogger'; import type {DisplayModeType} from './DisplayMode'; -import BatchedBridge from '../BatchedBridge/BatchedBridge'; +import registerCallableModule from '../Core/registerCallableModule'; import BugReporting from '../BugReporting/BugReporting'; import createPerformanceLogger from '../Utilities/createPerformanceLogger'; import infoLog from '../Utilities/infoLog'; @@ -363,8 +363,8 @@ global.RN$SurfaceRegistry = { if (global.RN$Bridgeless === true) { console.log('Bridgeless mode is enabled'); -} else { - BatchedBridge.registerCallableModule('AppRegistry', AppRegistry); } +registerCallableModule('AppRegistry', AppRegistry); + module.exports = AppRegistry; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/HeadlessJsTaskService.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/HeadlessJsTaskService.java index c5dfeb33de14f9..9fa6f58fe30775 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/HeadlessJsTaskService.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/HeadlessJsTaskService.java @@ -124,15 +124,11 @@ public void run() { @Override public void onDestroy() { super.onDestroy(); + ReactContext reactContext = getReactContext(); - if (getReactNativeHost().hasInstance()) { - ReactInstanceManager reactInstanceManager = getReactNativeHost().getReactInstanceManager(); - ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); - if (reactContext != null) { - HeadlessJsTaskContext headlessJsTaskContext = - HeadlessJsTaskContext.getInstance(reactContext); - headlessJsTaskContext.removeTaskEventListener(this); - } + if (reactContext != null) { + HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(reactContext); + headlessJsTaskContext.removeTaskEventListener(this); } if (sWakeLock != null) { sWakeLock.release();