From 64fb9294873b128a981a06dcda7c5f2babb092ec Mon Sep 17 00:00:00 2001 From: Alexander Pantiukhov Date: Tue, 17 Nov 2026 11:53:42 +0100 Subject: [PATCH 1/2] perf(android): Create SDK view managers on demand RNSentryPackage now implements ViewManagerOnDemandReactPackage. With the New Architecture, React Native builds the view configs of every eager package's view managers when JS first reads UIManager, on the JS thread before the first screen renders. On-demand packages only report their names, and React Native creates a view manager and builds its config the first time JS uses it. Apps that never render RNSentryOnDrawReporter, RNSentryReplayMask or RNSentryReplayUnmask no longer pay for their configs at startup. The gain needs React Native 0.89+, which keeps lazy view manager getters lazy (facebook/react-native@da7c29f). Older versions still create the managers through the same path. createViewManagers stays unchanged for setups that load view managers eagerly, such as the old architecture without lazy view managers. getViewManagerNames returns List so it compiles against both the Java (List/Collection) and Kotlin versions of the interface. --- CHANGELOG.md | 4 ++ .../io/sentry/react/RNSentryPackageTest.kt | 38 +++++++++++++++++++ .../java/io/sentry/react/RNSentryPackage.java | 28 +++++++++++++- 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 packages/core/RNSentryAndroidTester/app/src/test/java/io/sentry/react/RNSentryPackageTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index ddfaf21320..39eeffa350 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## Unreleased +### Features + +- Create the Android view managers of the SDK on demand, so React Native 0.89+ with the New Architecture does not build their view configs at startup ([#PR_NUMBER](https://github.com/getsentry/sentry-react-native/pull/PR_NUMBER)) + ### Fixes - Fix the TypeScript error `Cannot find module 'react-native/Libraries/Types/CodegenTypes'` with React Native 0.88 and `skipLibCheck: false` ([#7061](https://github.com/getsentry/sentry-react-native/pull/7061)) diff --git a/packages/core/RNSentryAndroidTester/app/src/test/java/io/sentry/react/RNSentryPackageTest.kt b/packages/core/RNSentryAndroidTester/app/src/test/java/io/sentry/react/RNSentryPackageTest.kt new file mode 100644 index 0000000000..46e66362e8 --- /dev/null +++ b/packages/core/RNSentryAndroidTester/app/src/test/java/io/sentry/react/RNSentryPackageTest.kt @@ -0,0 +1,38 @@ +package io.sentry.react + +import com.facebook.react.bridge.ReactApplicationContext +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertNull +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.mockito.kotlin.mock + +@RunWith(JUnit4::class) +class RNSentryPackageTest { + private val reactContext: ReactApplicationContext = mock() + private val sentryPackage = RNSentryPackage() + + @Test + fun `getViewManagerNames matches the eagerly created view managers`() { + val eagerNames = sentryPackage.createViewManagers(reactContext).map { it.name }.toSet() + + assertEquals(eagerNames, sentryPackage.getViewManagerNames(reactContext).toSet()) + } + + @Test + fun `createViewManager creates the view manager with the requested name`() { + for (name in sentryPackage.getViewManagerNames(reactContext)) { + val viewManager = sentryPackage.createViewManager(reactContext, name) + + assertNotNull("No view manager for $name", viewManager) + assertEquals(name, viewManager?.name) + } + } + + @Test + fun `createViewManager returns null for an unknown name`() { + assertNull(sentryPackage.createViewManager(reactContext, "UnknownViewManager")) + } +} diff --git a/packages/core/android/src/main/java/io/sentry/react/RNSentryPackage.java b/packages/core/android/src/main/java/io/sentry/react/RNSentryPackage.java index 40941df3c8..1c88dc58c5 100644 --- a/packages/core/android/src/main/java/io/sentry/react/RNSentryPackage.java +++ b/packages/core/android/src/main/java/io/sentry/react/RNSentryPackage.java @@ -3,6 +3,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.facebook.react.TurboReactPackage; +import com.facebook.react.ViewManagerOnDemandReactPackage; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.module.model.ReactModuleInfo; @@ -16,7 +17,7 @@ import java.util.List; import java.util.Map; -public class RNSentryPackage extends TurboReactPackage { +public class RNSentryPackage extends TurboReactPackage implements ViewManagerOnDemandReactPackage { private static final boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; @@ -99,4 +100,29 @@ public List createViewManagers(ReactApplicationContext reactContext new RNSentryReplayMaskManager(), new RNSentryReplayUnmaskManager()); } + + @NonNull + @Override + public List getViewManagerNames(@NonNull ReactApplicationContext reactContext) { + return List.of( + RNSentryOnDrawReporterManager.REACT_CLASS, + RNSentryReplayMaskManagerImpl.REACT_CLASS, + RNSentryReplayUnmaskManagerImpl.REACT_CLASS); + } + + @Nullable + @Override + public ViewManager createViewManager( + @NonNull ReactApplicationContext reactContext, @NonNull String viewManagerName) { + switch (viewManagerName) { + case RNSentryOnDrawReporterManager.REACT_CLASS: + return new RNSentryOnDrawReporterManager(reactContext); + case RNSentryReplayMaskManagerImpl.REACT_CLASS: + return new RNSentryReplayMaskManager(); + case RNSentryReplayUnmaskManagerImpl.REACT_CLASS: + return new RNSentryReplayUnmaskManager(); + default: + return null; + } + } } From 72c12b6dfb78b505eddf7e3b62def04f768f9d02 Mon Sep 17 00:00:00 2001 From: Alexander Pantiukhov Date: Tue, 17 Nov 2026 13:50:56 +0100 Subject: [PATCH 2/2] docs(changelog): Link on-demand view managers entry to its PR Replace the PR_NUMBER placeholder with #7049 now that the PR exists. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39eeffa350..7285dfa302 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ ### Features -- Create the Android view managers of the SDK on demand, so React Native 0.89+ with the New Architecture does not build their view configs at startup ([#PR_NUMBER](https://github.com/getsentry/sentry-react-native/pull/PR_NUMBER)) +- Create the Android view managers of the SDK on demand, so React Native 0.89+ with the New Architecture does not build their view configs at startup ([#7049](https://github.com/getsentry/sentry-react-native/pull/7049)) ### Fixes