fix(android): identify the screen appear event by name instead of class - #6692
Open
TaduJR wants to merge 1 commit into
Open
fix(android): identify the screen appear event by name instead of class#6692TaduJR wants to merge 1 commit into
TaduJR wants to merge 1 commit into
Conversation
TaduJR
requested review from
alwx,
antonis and
lucas-zimerman
as code owners
September 9, 2026 18:06
TaduJR
marked this pull request as draft
September 9, 2026 18:07
TaduJR
force-pushed
the
fix/android-ttid-event-name-matching
branch
from
September 9, 2026 18:13
3132d3b to
f2bffa1
Compare
TaduJR
force-pushed
the
fix/android-ttid-event-name-matching
branch
from
September 9, 2026 18:21
f2bffa1 to
77a2d2d
Compare
TaduJR
marked this pull request as ready for review
September 9, 2026 18:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📢 Type of change
📜 Description
RNSentryReactFragmentLifecycleTracerwaited for the react-native-screens appear event by comparing its canonical class name:Class names are not stable once R8 optimization is on. React Native
Eventsubclasses share a superclass and a constructor signature, which makes them candidates for merging, and R8 collapses a group of them into one class that answers to a single name. It also rewrites the compared string literal to that name, so the comparison then matches every event in the group rather than one.The event is now identified by
Event.getEventName(), which React Native documents as "the name of this event as registered in JS". react-native-screens registerstopAppearas theonAppearprop, so the name is part of its public contract and cannot change without breaking it. Unoptimized builds behave exactly as before.The sibling check against
com.swmansion.rnscreens.ScreenStackFragmentis left as is. androidx.fragment ships a consumer rule that keeps publicFragmentsubclasses with a public no-arg constructor, and Android requires that constructor for fragment recreation, so that class is never merged.💡 Motivation and Context
Fixes #6691
With R8 optimization enabled,
ui.load.initial_displaycloses on whichever merged event dispatches first rather than on the screen appear event.topWillAppearalways precedestopAppear, and events such astopFocusandtopAttachedcan precede both, so time to initial display is reported shorter than it was. Nothing throws, and every diagnostic on this path logs atSentryLevel.DEBUG, so the data is wrong silently.This affects any app that enables optimization, which AGP 9 makes the default by dropping support for the ProGuard file that carried
-dontoptimize.Reproduction: REPRO_URL. Four dependencies, no patched libraries, the R8 that AGP ships. There
ScreenAppearEventis merged into React Native's ownDrawerClosedEvent, and the merged class holds 22 event names behind one class name.💚 How did you test it?
Added unit tests to
RNSentryReactFragmentLifecycleTracerTest, which previously covered listener registration but not which event triggers the first draw. One asserts thattopAppearregisters the first draw listener and removes the event listener, one asserts thattopWillAppeardoes neither.The reported behaviour was confirmed by disassembling the release dex of the reproduction, where the compared literal had been rewritten to the merged class name.
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
An alternative that needs no code change is to ship
-keep class com.swmansion.rnscreens.events.ScreenAppearEventas a consumer ProGuard rule in the SDK. That keeps the class name intact but leaves the identity check dependent on the optimizer, which is why matching by event name is proposed instead.