RUMS-5996: Fix ANR in old-arch SR text mapper #1296
Merged
jonathanmos merged 3 commits intoJun 2, 2026
Merged
Conversation
This comment has been minimized.
This comment has been minimized.
746e751 to
e83f6e7
Compare
… shadow node fetch
e83f6e7 to
db7dfe6
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses an ANR in React Native old architecture Session Replay text mapping by removing the UI-thread-blocking shadow node resolution path and instead deriving text styling directly from the TextView (via Spanned spans and typeface fallback), aligning behavior more closely with the existing Fabric/new-arch mapper.
Changes:
- Removed
ShadowNodeWrapper(and related reflection/UIManager shadow-node access) from the legacy text mapper to avoid blocking the UI thread. - Updated
LegacyTextViewUtilsto resolve font family (viaCustomStyleSpanreflection), font size (viaAbsoluteSizeSpan/TextView.textSize), and text color (viaForegroundColorSpan) directly from theTextView. - Refactored and expanded JVM tests to validate the new span/typeface-based resolution behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/react-native-session-replay/android/src/test/kotlin/com/datadog/reactnative/sessionreplay/utils/text/TextViewUtilsTest.kt | Updates tests to cover span/typeface-based style resolution and removes shadow-node based setup. |
| packages/react-native-session-replay/android/src/main/kotlin/com/datadog/reactnative/sessionreplay/utils/text/TextViewUtils.kt | Removes legacy ReflectionUtils dependency and updates factory creation for legacy implementation. |
| packages/react-native-session-replay/android/src/main/kotlin/com/datadog/reactnative/sessionreplay/utils/text/LegacyTextViewUtils.kt | Replaces shadow-node lookups with direct TextView/Spanned inspection and reflection on CustomStyleSpan. |
| packages/react-native-session-replay/android/src/main/kotlin/com/datadog/reactnative/sessionreplay/ShadowNodeWrapper.kt | Deletes the blocking shadow-node wrapper implementation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
sbarrio
approved these changes
Jun 2, 2026
4 tasks
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.
What does this PR do?
Fixes an ANR on Android on the React Native old architecture caused by the Session Replay text mapper blocking the UI thread on every TextView in a snapshot.
Root cause: LegacyTextViewUtils fetched RN text properties (font family, size, color) by posting a runnable to mqt_native_modules and synchronously blocking the UI thread on a CountDownLatch for up to 5 seconds via ShadowNodeWrapper.getShadowNodeWrapper. If mqt_native_modules was busy (e.g. mid-UIManagerModule.onBatchComplete / Yoga layout — the very batch whose redraw triggered the snapshot), the posted runnable queued behind that work and the UI thread waited. With even a handful of TextViews on screen, the cumulative wait exceeded the 5-second input-dispatch deadline and the system fired an ANR.
Fix: Removed ShadowNodeWrapper entirely from the old-arch text mapper. All three text properties are now read directly off the TextView, matching what FabricTextViewUtils already does:
Font size: view.textSize (unchanged, was already correct)
Text color: read from ForegroundColorSpan on the view's Spanned text (RN old arch encodes color as a span, not via TextView.setTextColor())
Font family: read from CustomStyleSpan via Class.forName + reflection (RN old arch applies font family to TextPaint at draw time via this span, never via TextView.setTypeface())
FabricTextViewUtils (new architecture) is not affected — it already reads directly from the TextView with no cross-thread calls.
Motivation
What inspired you to submit this pull request?
Additional Notes
Anything else we should know when reviewing?
Review checklist (to be filled by reviewers)