From 3aa8a043de283f539cc907c7a5368e61cecb35b9 Mon Sep 17 00:00:00 2001 From: Shubham Kumar Savita Date: Sat, 7 Mar 2026 20:19:22 -0800 Subject: [PATCH] Fix onHostPause crash in ReactInstanceManager without feature flag (#55986) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55986 This fixes the `java.lang.AssertionError` crash in `ReactInstanceManager.onHostPause()` for third-party React Native apps (primarily Discord at 95.9% of crashes) using the deprecated bridge mode. ## Problem When VROS triggers Activity lifecycle transitions that cause two Activity instances to exist simultaneously, the reference equality assertion in `onHostPause()` crashes. D95309454 attempted to fix this by gating behind `ReactNativeFeatureFlags.skipActivityIdentityAssertionOnHostPause()`, but that flag has `ossReleaseStage: 'none'`, meaning OSS users can't benefit from the fix. ## Solution Instead of gating behind a feature flag, always log a warning instead of crashing with an assertion. This is safe because: - `ReactInstanceManager` is deprecated bridge-mode code - The flag's `expectedReleaseValue` is `true` (intended to always skip the assertion) - The bridgeless architecture (`ReactHostImpl.kt`) already has the same behavior - This avoids the GitHub export issue where the flag defaults to `false` for OSS ## Stats - 365 crashes in 14 days across 8 third-party apps - All Quest devices affected (Q2, Q3, Q3S) - All active branches (v85, v201, v83) ## Changes - Modified `onHostPause()` to log a warning via `FLog.w()` instead of crashing via `Assertions.assertCondition()` when the paused activity doesn't match the current activity - Added null safety for the activity parameter in the log message - No new imports needed (removed dependency on `ReactNativeFeatureFlags`) Reviewed By: cortinico Differential Revision: D95570941 fbshipit-source-id: 2fc377c3ace97d328e8b8cc195e3a30069d0c2aa --- .../facebook/react/ReactInstanceManager.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java index 1b1bd1e8c7e..fe01cba8ea6 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java @@ -27,6 +27,7 @@ import static com.facebook.react.bridge.ReactMarkerConstants.VM_INIT; import static com.facebook.react.uimanager.common.UIManagerType.FABRIC; import static com.facebook.systrace.Systrace.TRACE_TAG_REACT; +import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -593,12 +594,14 @@ public class ReactInstanceManager { /** * Call this from {@link Activity#onPause()}. This notifies any listening modules so they can do - * any necessary cleanup. The passed Activity is the current Activity being paused. This will - * always be the foreground activity that would be returned by {@link - * ReactContext#getCurrentActivity()}. + * any necessary cleanup. The passed Activity is the current Activity being paused. This is + * expected to be the foreground activity that would be returned by {@link + * ReactContext#getCurrentActivity()}. If the passed activity does not match the current activity, + * a warning will be logged instead of crashing. * * @param activity the activity being paused */ + @SuppressLint("ReflectionMethodUse") @ThreadConfined(UI) public void onHostPause(@Nullable Activity activity) { if (mRequireActivity) { @@ -612,15 +615,15 @@ public class ReactInstanceManager { } Assertions.assertCondition(mCurrentActivity != null); } - if (mCurrentActivity != null) { - Assertions.assertCondition( - activity == mCurrentActivity, + if (mCurrentActivity != null && activity != mCurrentActivity) { + FLog.w( + TAG, "Pausing an activity that is not the current activity, this is incorrect! " + "Current activity: " + mCurrentActivity.getClass().getSimpleName() + " " + "Paused activity: " - + activity.getClass().getSimpleName()); + + (activity == null ? "null" : activity.getClass().getSimpleName())); } onHostPause(); }