Skip to content

Android: time to initial display is understated in R8-optimized builds because the screen appear event is matched by class name #6691

Closed

Description

@TaduJR

What React Native libraries do you use?

React Navigation, Hermes, RN New Architecture

Are you using sentry.io or on-premise?

sentry.io

Are you using any other error monitoring solution alongside Sentry?

Yes

Other Error Monitoring Solution Name

FullStory

@sentry/react-native SDK Version

8.25.0

How does your development environment look like?

React Native 0.86.3, Hermes, New Architecture enabled
@sentry/react-native 8.25.0
react-native-screens 4.27.0
@react-navigation/native-stack 7.18.10
Android Gradle Plugin with its bundled R8 8.12.14, no pinned compiler
JDK 17
Release build with minifyEnabled true and proguard-android-optimize.txt, which is the React Native template default

Sentry.init()

const navigationIntegration = Sentry.reactNavigationIntegration({
  enableTimeToInitialDisplay: true,
});

Sentry.init({
  dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
  tracesSampleRate: 1.0,
  enableAutoPerformanceTracing: true,
  integrations: [navigationIntegration],
});

Steps to Reproduce

Minimal reproduction: https://github.com/TaduJR/sentry-ttid-r8-repro. Four dependencies, no patched libraries, default React Native release configuration, the R8 that AGP ships, no pinned compiler.

  1. npm install
  2. cd android && ./gradlew assembleRelease
  3. grep ScreenAppearEvent android/app/build/outputs/mapping/release/mapping.txt
  4. apkanalyzer dex code --class G2.a android/app/build/outputs/apk/release/app-release.apk

Step 3 returns a single method line that sits inside the entry for com.facebook.react.views.drawer.events.DrawerClosedEvent, because a class that is merged away gets no header of its own. Step 4 shows that class carrying a synthetic discriminator field and a switch over 22 event names.

Equivalent by hand: use a React Navigation native stack so react-native-screens creates ScreenStackFragment, enable reactNavigationIntegration({enableTimeToInitialDisplay: true}), build a release with proguard-android-optimize.txt, and disassemble the listener that RNSentryReactFragmentLifecycleTracer installs.

Expected Result

The listener waits for the screen appear event, so ui.load.initial_display closes when the screen is actually drawn.

Actual Result

RNSentryReactFragmentLifecycleTracer identifies the event by canonical class name:

if ("com.swmansion.rnscreens.events.ScreenAppearEvent"
    .equals(event.getClass().getCanonicalName())) {

Class names are not stable under R8. Horizontal class merging collapses identically shaped classes into one, and React Native Event subclasses share a superclass and a constructor signature, which makes them candidates for merging.

In the linked reproduction, ScreenAppearEvent is merged into React Native's own DrawerClosedEvent, obfuscated to G2.a. The merged class carries a synthetic discriminator field and a switch over 22 event names:

.field public final synthetic l:I

iget v0, p0, LG2/a;->l:I
packed-switch v0, :pswitch_data_42
    "topAppear"  "topWillAppear"  "topDisappear"  "topWillDisappear"  "topDismissed"
    "topFocus"   "topAttached"    "topDetached"   "topOpen"           "topClose"
    "topSearchFocus"  "topSearchBlur"  "topFinishTransitioning"
    "topHeaderBackButtonClicked"  "topClick"  "topRefresh"  "topShow"
    "topRequestClose"  "topDrawerOpen"  "topDrawerClose"  "dismissCount"  "target"

R8 rewrote the string literal to follow the merge, so the shipped comparison is against G2.a.

All 22 are the same class at runtime, so the check matches on whichever dispatches first after the fragment view is created. topWillAppear always precedes topAppear, and topFocus and topAttached can precede both. The first draw listener is registered too early and the initial display span closes early, so time to initial display is reported shorter than it was.

This is silent. Every diagnostic on this path logs at SentryLevel.DEBUG, and nothing throws.

Two notes for anyone verifying this. The mapping file shows nothing at the class level, so grep ScreenAppearEvent mapping.txt looks clean unless you read the method lines inside other classes, and only the dex is reliable. react-native-screens ships no consumer ProGuard rules, so nothing protects the event class in a consuming app.

The sibling check against com.swmansion.rnscreens.ScreenStackFragment is not affected. androidx.fragment ships a consumer rule keeping public Fragment subclasses that have a public no-arg constructor, so that class is never merged.

Activity

  1. linear-code commented on Sep 9, 2026

    @linear-code
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Sep 9, 2026
  3. self-assigned this
    on Sep 10, 2026
  4. alwx commented on Sep 10, 2026

    @alwx
    Contributor

    @TaduJR

    Thanks for reporting. I've seen both this issue and the PR aiming to resolve it, and added a comment to the PR itself.

  5. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Sep 10, 2026
  6. github-actions commented on Sep 10, 2026

    @github-actions
    Contributor

    A PR closing this issue has just been released 🚀

    This issue was referenced by PR #6692, which was included in the 8.26.0 release.

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

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions