Hii, Im facing this Crash - Compose Runtime crash:...
# compose
s
Hii, Im facing this Crash - Compose Runtime crash: re-entrant subcomposition via Android focus system during AndroidView removal in LazyStaggeredGrid
64 crashes for 51 users in the last 24 hours
We're hitting a fatal crash in production (Compose Multiplatform 1.10.0, Compose Runtime 1.7.x): Compose Runtime internal error. Unexpected or incorrect use of the Compose internal runtime API (pending composition has not been applied) Setup: AndroidView (Google NativeAdView for ads) inside a LazyVerticalStaggeredGrid. The crash occurs when grid content changes (e.g. switching category/filter), causing ad items to be removed. Crash chain:
Copy code
1. Compose applies changes → RemoveNode → UiApplier.remove → LayoutNode.detach
2. AndroidComposeView.removeAndroidView → ViewGroup.removeViewInLayout
3. Android focus system fires synchronously: rootViewRequestFocus → requestFocus
4. AndroidComposeView.requestFocusBypassUnfocusableComposeView → focusSearch → twoDimensionalFocusSearch
5. searchBeyondBounds → LazyLayoutBeyondBoundsProviderModifierNode.layout → remeasureSync → forceRemeasure
6. SubcomposeLayout.subcompose → composeInitial → drainPendingModificationsForCompositionLocked → CRASH
Root issue: Compose doesn't guard against re-entrant subcomposition triggered by Android's native focus system during applyChangesInLocked. The focus cascade from removeViewInLayout is synchronous and escapes the Compose runtime's control. Workaround: Adding focusProperties { canFocus = false } to the AndroidView modifier + FOCUS_BLOCK_DESCENDANTS on the native view. This prevents focus search from entering the ad subtree. Question: Is this a known issue? Should the runtime guard against re-entrant composition from the focus system during the apply phase?
s
This was reported already, the workaround is to enable one of the focus flags in ComposeUiFlags (something view bypass focus, don't remember exact name, sorry)
s
@shikasd thanks ill try that, also is there a fix planned for this in the upcoming release?
s
Not sure, maybe @Alex Vanyo knows better
s
@shikasd these are the 2 flags? -
isRemoveFocusedViewFixEnabled
&
isGetFocusedRectReturnEmptyEnabled
s
isBypassUnfocusableComposeViewEnabled
already defaults to true in our Compose UI 1.10.2, but we're still hitting the crash. The specific path is: AndroidView (NativeAdView) inside
LazyVerticalStaggeredGrid
is removed during content change →
removeViewInLayout
rootViewRequestFocus
requestFocusBypassUnfocusableComposeView
searchBeyondBounds
→ re-entrant subcompose → crash. Should we also try
isViewFocusFixEnabled
= true? Or is this a gap in the current bypass flag's coverage? @shikasd, sorry in advance to tag you again, just that now the crashes are above 100 for 90 users for the last 24 hours, thanks again already for all the help
s
maybe you need to disable it then? I don't remember the specifics, sorry https://issuetracker.google.com/issues/469958424#comment5
🙏 1
s
Update: Applied the workaround
ComposeUiFlags.isBypassUnfocusableComposeViewEnabled = false
in
Application.onCreate()
, before
super.onCreate()
Build verified. Shipping in the next release. For anyone following: this matches the recommendation in issuetracker.google.com/469958424#comment5 from the Compose UI team. Another company confirmed no side effects with ~200K users (comment #8). Google is actively working on removing this flag entirely (comment #6). Thanks, @shikasd, for the quick pointer. It saved us a lot of debugging time. Hopefully, now i wont see this issue in the crashlytics 🤞
a
Yep that workaround looks the right now, the underlying issue is a thorny one so no estimate right now for when it'll be fixed without needing the workaround
🙏 1
s
Just want to say thanks again for all the help. No crashes have been reported so far in the latest release. Thanks again.