Skip to content

Commit 3aa8a04

Browse files
shubhamksavitameta-codesync[bot]
authored andcommitted
Fix onHostPause crash in ReactInstanceManager without feature flag (#55986)
Summary: Pull Request resolved: #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
1 parent c0b1057 commit 3aa8a04

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static com.facebook.react.uimanager.common.UIManagerType.FABRIC;
2828
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT;
2929

30+
import android.annotation.SuppressLint;
3031
import android.app.Activity;
3132
import android.content.Context;
3233
import android.content.Intent;
@@ -593,12 +594,14 @@ public void onUserLeaveHint(@Nullable Activity activity) {
593594

594595
/**
595596
* Call this from {@link Activity#onPause()}. This notifies any listening modules so they can do
596-
* any necessary cleanup. The passed Activity is the current Activity being paused. This will
597-
* always be the foreground activity that would be returned by {@link
598-
* ReactContext#getCurrentActivity()}.
597+
* any necessary cleanup. The passed Activity is the current Activity being paused. This is
598+
* expected to be the foreground activity that would be returned by {@link
599+
* ReactContext#getCurrentActivity()}. If the passed activity does not match the current activity,
600+
* a warning will be logged instead of crashing.
599601
*
600602
* @param activity the activity being paused
601603
*/
604+
@SuppressLint("ReflectionMethodUse")
602605
@ThreadConfined(UI)
603606
public void onHostPause(@Nullable Activity activity) {
604607
if (mRequireActivity) {
@@ -612,15 +615,15 @@ public void onHostPause(@Nullable Activity activity) {
612615
}
613616
Assertions.assertCondition(mCurrentActivity != null);
614617
}
615-
if (mCurrentActivity != null) {
616-
Assertions.assertCondition(
617-
activity == mCurrentActivity,
618+
if (mCurrentActivity != null && activity != mCurrentActivity) {
619+
FLog.w(
620+
TAG,
618621
"Pausing an activity that is not the current activity, this is incorrect! "
619622
+ "Current activity: "
620623
+ mCurrentActivity.getClass().getSimpleName()
621624
+ " "
622625
+ "Paused activity: "
623-
+ activity.getClass().getSimpleName());
626+
+ (activity == null ? "null" : activity.getClass().getSimpleName()));
624627
}
625628
onHostPause();
626629
}

0 commit comments

Comments
 (0)