Skip to content

Guard LogBox dialog dismiss against detached window - #56765

Open
aroravarun wants to merge 1 commit into
react:mainfrom
aroravarun:export-D104391294
Open

Guard LogBox dialog dismiss against detached window#56765
aroravarun wants to merge 1 commit into
react:mainfrom
aroravarun:export-D104391294

Conversation

@aroravarun

Copy link
Copy Markdown

Summary:
LogBoxDialogSurfaceDelegate.hide() calls dialog.dismiss() whenever
dialog.isShowing is true, but the host Activity's window can be torn
down between the dispatch of LogBoxModule.hide() and the Handler
callback that runs hide(). When that race hits, Dialog.dismiss()
routes to WindowManagerImpl.removeViewImmediate, which throws
IllegalArgumentException: View ... not attached to window manager
and crashes the process.

Add an isAttachedToWindow check on the dialog's DecorView so the
dismiss is skipped once the host window is gone. The dialog reference
is still nulled and destroyContentView() still runs, so React state
is cleaned up correctly.

Changelog:
[Android][Fixed] - Avoid IllegalArgumentException when LogBox dismisses after the host Activity is destroyed

Differential Revision: D104391294

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 11, 2026
@meta-codesync

meta-codesync Bot commented May 11, 2026

Copy link
Copy Markdown

@aroravarun has exported this pull request. If you are a Meta employee, you can view the originating Diff in D104391294.

Summary:
`LogBoxDialogSurfaceDelegate.hide()` calls `dialog.dismiss()` whenever
`dialog.isShowing` is true, but the host Activity's window can be torn
down between the dispatch of `LogBoxModule.hide()` and the Handler
callback that runs `hide()`. When that race hits, `Dialog.dismiss()`
routes to `WindowManagerImpl.removeViewImmediate`, which throws
`IllegalArgumentException: View ... not attached to window manager`
and crashes the process.

Add an `isAttachedToWindow` check on the dialog's DecorView so the
dismiss is skipped once the host window is gone. The dialog reference
is still nulled and `destroyContentView()` still runs, so React state
is cleaned up correctly.

Changelog:
[Android][Fixed] - Avoid IllegalArgumentException when LogBox dismisses after the host Activity is destroyed

Differential Revision: D104391294
@aroravarun
aroravarun force-pushed the export-D104391294 branch from 16c561c to 7efe1c8 Compare May 11, 2026 12:04
@ramyjaiem

Copy link
Copy Markdown

Independent real-device report matching this failure:

  • React Native 0.86.3 via Expo SDK 57.0.19
  • Hermes + New Architecture in an Expo development client
  • Xiaomi 2509FPN0BC on Android 16 (HyperOS OS3.0.315.0.WPBCNXM)
  • The crash was observed after development reload/background transitions; I have not yet reduced it to a deterministic minimal reproduction
java.lang.IllegalArgumentException: View=...DecorView...[MainActivity] not attached to window manager
    at android.view.WindowManagerGlobal.findViewLocked(...)
    at android.view.WindowManagerGlobal.removeView(...)
    at android.view.WindowManagerImpl.removeViewImmediate(...)
    at android.app.Dialog.dismissDialog(...)
    at android.app.Dialog$$ExternalSyntheticLambda0.run(...)
    at android.os.Handler.handleCallback(...)

The Dialog$$ExternalSyntheticLambda0 frame is consistent with dismiss() being posted to the dialog Handler and running after the Activity window detached. The proposed decorView.isAttachedToWindow guard directly covers that state.

I also confirmed the unguarded LogBoxDialogSurfaceDelegate.hide() path is present in React Native 0.86.3. Could this be considered for an 0.86 backport once merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants