[RUM-11630] Support SVG in Session Replay#985
Merged
cdn34dd merged 44 commits intoOct 22, 2025
Conversation
cdn34dd
force-pushed
the
carlosnogueira/RUM-11630/react-native-sr-svg-support
branch
from
September 16, 2025 11:21
9a73098 to
1a4f6ec
Compare
cdn34dd
force-pushed
the
carlosnogueira/RUM-11630/react-native-sr-svg-support
branch
6 times, most recently
from
October 6, 2025 15:00
b539a74 to
7228edb
Compare
sbarrio
reviewed
Oct 13, 2025
sbarrio
reviewed
Oct 13, 2025
sbarrio
reviewed
Oct 13, 2025
sbarrio
reviewed
Oct 13, 2025
sbarrio
reviewed
Oct 13, 2025
sbarrio
reviewed
Oct 13, 2025
marco-saia-datadog
self-requested a review
October 13, 2025 09:27
marco-saia-datadog
requested changes
Oct 13, 2025
marco-saia-datadog
left a comment
Member
There was a problem hiding this comment.
Amazing work 💯 the code looks good to me, and is very well documented, thank you! 🙌
I've left a few comments, some are minor nits and a couple are more important points to consider.
cdn34dd
force-pushed
the
carlosnogueira/RUM-11630/react-native-sr-svg-support
branch
2 times, most recently
from
October 15, 2025 11:05
4e46b59 to
80c0caf
Compare
cdn34dd
marked this pull request as ready for review
October 15, 2025 11:07
OliviaShoup
previously approved these changes
Oct 15, 2025
OliviaShoup
left a comment
There was a problem hiding this comment.
looks great. thanks for the update!
cdn34dd
force-pushed
the
carlosnogueira/RUM-11630/react-native-sr-svg-support
branch
2 times, most recently
from
October 15, 2025 22:52
3877d16 to
1786b82
Compare
sbarrio
previously approved these changes
Oct 16, 2025
mariedm
reviewed
Oct 16, 2025
cdn34dd
changed the base branch from
carlosnogueira/RUM-11710/session-replay-svg
to
develop
October 16, 2025 17:56
cdn34dd
dismissed stale reviews from sbarrio and OliviaShoup
October 16, 2025 17:56
The base branch was changed.
…es for clarity and consistency
…nsform properties from style objects
- Ensure assets directory in Session Replay package is cleaned up when `yarn prepare` is ran so no unwanted files get packed
- Only do data checks if the view in question is our custom SesssionReplayView - Remove accessibilityIdentifier check as it's not needed - Update file reading logic to support <iOS 13
- This will improve performance when the plugin is ran on metro, as it will first load the data from that file if present, avoiding runtime parsing
cdn34dd
force-pushed
the
carlosnogueira/RUM-11630/react-native-sr-svg-support
branch
from
October 22, 2025 11:32
bbec80b to
7513690
Compare
cdn34dd
force-pushed
the
carlosnogueira/RUM-11630/react-native-sr-svg-support
branch
from
October 22, 2025 11:56
7513690 to
7f07490
Compare
cdn34dd
force-pushed
the
carlosnogueira/RUM-11630/react-native-sr-svg-support
branch
from
October 22, 2025 13:11
78eee70 to
72d80ab
Compare
marco-saia-datadog
self-requested a review
October 22, 2025 13:16
marco-saia-datadog
approved these changes
Oct 22, 2025
cdn34dd
deleted the
carlosnogueira/RUM-11630/react-native-sr-svg-support
branch
October 22, 2025 13:49
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?
This PR adds support for tracking SVG images in React Native Session Replay.
This PR is composed of 3 main components that work together to create a workflow that enables SVGs to be captured in Session Replay:
@datadog/mobile-react-native-babel-pluginpackage)@datadog/mobile-react-native-session-replaypackage)@datadog/mobile-react-native-babel-pluginpackage)Babel Plugin
The Babel plugin feature is the core of this PR, containing most of the complexity. Its main responsibilities are to:
What kind of SVGs does the plugin handle?
To correctly identify and extract SVGs in a user's codebase, the plugin differentiates between three types of SVGs and handles each appropriately:
1. Inline SVGs
SVGs built directly in the codebase using elements from the react-native-svg library (e.g.,
<Svg>,<Path>,<Circle>). These require the most complex logic for full extraction and transformation.Example:
2. External SVGs (Local)
SVGs loaded from the user's filesystem. These are typically already in web-compliant format, but the plugin needs to properly identify them in the user's code since they can be named anything.
Example:
3. External SVGs (Remote)
SVGs loaded from external servers using the SvgUri component from react-native-svg.
Example:
What kind of SVGs do we still need to support?
The plugin currently handles direct usage of
react-native-svgelements and loading SVG files directly. The main area for future expansion is adding support for popular SVG libraries built on top ofreact-native-svg, such as:The groundwork to support these libraries is already in place, as the logic should be similar to handling local SVGs (treating library-generated SVGs as specialized local SVG cases).
Areas of Improvement
Some areas for future enhancement that didn't make it into this first release:
All of these improvements are feasible with sufficient time allocation.
Metro Plugin
The Metro plugin (
withSessionReplayAssetBundler) integrates with React Native's Metro bundler to automatically aggregate SVG assets during development and production builds.Key responsibilities:
assets.bin) with an accompanying JSON index (assets.json) for efficient native lookupbundle_build_doneandtransformer_load_doneHow it works:
The Metro plugin wraps the Metro config's reporter and watches for new .svg files in the
packages/react-native-session-replay/assets/ directory. When new SVG assets are detected (either from the Babel plugin or the CLI utility), it packs them into:
assets.bin- A binary file containing all SVG data concatenated togetherassets.json- An index mapping SVG IDs to their byte offset and length in the binary fileThis approach allows the native SDKs to efficiently load SVG assets by reading specific byte ranges from a single file rather than managing hundreds of individual files.
CLI Utility
The CLI utility (
npx datadog-generate-sr-assets) provides a way to pre-generate all Session Replay SVG assets before native builds.Key responsibilities:
When to use it:
The CLI utility should be run after installing dependencies and before building iOS/Android apps:
After installing dependencies
yarn installGenerate SVG assets
npx datadog-generate-sr-assetsThen build native apps
cd ios && pod install && cd ..This ensures that native asset references are available during the build process, particularly important for iOS where the
assets need to be included in the Xcode project.
What it does:
.js,.jsx,.ts, and.tsxfiles (excludingnode_modules, test files, etc.)How does this all work together?
Here's the complete workflow for integrating SVG support in your React Native app:
1. Setup the Babel Plugin
Configure the Babel plugin in your
babel.config.jsto enable SVG tracking:2. Setup the Metro Plugin
Configure the Metro plugin in your
metro.config.jsto enable asset bundling:3. Generate Assets Before Native Builds
Run the CLI utility after installing dependencies and before building native apps:
Install dependencies
yarn installGenerate Session Replay SVG assets
npx datadog-generate-sr-assetsBuild iOS (if needed)
cd ios && pod install && cd ..Now you can run your app
yarn iosor
yarn android4. Development Workflow
During development, the Metro plugin automatically handles new SVG assets created by the Babel plugin:
react-native-svgThis ensures that SVGs are seamlessly captured in Session Replay without requiring manual asset management.