Uh oh!
There was an error while loading. Please reload this page.
RUM-12185: Support aliased import paths for local SVG discovery - #1352
RUM-12185: Support aliased import paths for local SVG discovery#1352jonathanmos wants to merge 1 commit into
Conversation
🎉 All green!🧪 All tests passed 🔄 Datadog auto-retried 5 jobs - 4 passed on retry 🔗 Commit SHA: ffa6d6f | Docs | Datadog PR Page | Give us feedback! |
1a97eab to
ffa6d6fCompareThere was a problem hiding this comment.
Pull request overview
Adds support for resolving aliased local .svg imports during Session Replay asset discovery, so ReactNativeSVG.buildSvgMap() can map SVG components even when imports use TS/JS path mappings or babel-plugin-module-resolver.
Changes:
- Introduces
PathAliasResolverto resolve non-relative SVG import specifiers viababel-plugin-module-resolverandtsconfig.json/jsconfig.jsonpaths. - Updates
ReactNativeSVG.buildSvgMap()to use the resolver (and reset cached alias config between runs). - Adds regression tests and a benchmark scenario exercising aliased SVG imports.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| yarn.lock | Adds lock entries for tsconfig-paths and babel-plugin-module-resolver (and transitive deps). |
| packages/react-native-babel-plugin/test/react-native-svg.test.ts | Adds coverage for alias resolution via tsconfig/jsconfig + babel-module-resolver, and precedence/fallback behavior. |
| packages/react-native-babel-plugin/src/libraries/react-native-svg/pathAliasResolver.ts | New resolver implementing alias lookup via Babel partial config + tsconfig-paths. |
| packages/react-native-babel-plugin/src/libraries/react-native-svg/index.ts | Wires alias resolution into buildSvgMap() via resolveImportSource(). |
| packages/react-native-babel-plugin/package.json | Adds tsconfig-paths dependency and babel-plugin-module-resolver devDependency. |
| benchmarks/src/scenario/SessionReplay/component/Svg.tsx | Adds an aliased SVG import case (Group H) to the benchmark test screen. |
| benchmarks/package.json | Adds babel-plugin-module-resolver for the benchmark app. |
| benchmarks/babel.config.js | Configures module-resolver alias used by the benchmark aliased SVG case. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| @@ -60,6 +61,7 @@ | |||
| "@swc/core": "^1.13.21", | |||
| "@swc/jest": "^0.2.38", | |||
| "@types/jest": "^30.0.0", | |||
| "babel-plugin-module-resolver": "^5.0.2", | |||
| "jest": "^29.7.0", | |||
| "react-native-builder-bob": "0.26.0", | |||
| "tsc-alias": "^1.8.16", | |||
There was a problem hiding this comment.
We're adding new dependencies, make sure these are listed here: LICENSE-3rdparty.csv
| "@swc/core": "^1.13.21", | ||
| "@swc/jest": "^0.2.38", | ||
| "@types/jest": "^30.0.0", | ||
| "babel-plugin-module-resolver": "^5.0.2", |
There was a problem hiding this comment.
SInce the benchmark already uses this dependency, we should also use "5.0.2" here (remove the ^) as leaving it there could lead to duplicate dependencies. EX:. 5.0.2 and 5.0.3
| if (!resolved || !isRelativePath(resolved)) { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
What about absolute paths ? (probably not common), but maybe computed paths should be handled, check the Metro example above ?
| const source = path.node.source?.value; | ||
| if (!source?.endsWith('.svg')) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
I believe this may not work, if we have something like this:
alias: {
'@logo': './src/assets/logo.svg'
}
and then import it like so:
import Logo from '@logo';
There won't be an .svg in the import statement.
| * Resolves non-relative import specifiers (e.g. `@components/Logo`) against a | ||
| * project's `babel-plugin-module-resolver` config and/or its | ||
| * `tsconfig.json`/`jsconfig.json` `paths` mapping, so aliased local SVG | ||
| * imports can be found on disk the same way they resolve at runtime. | ||
| * | ||
| * Callers should still fall back to plain relative resolution when this | ||
| * returns `null` -- that covers projects that don't use any aliasing. | ||
| */ |
There was a problem hiding this comment.
What about those set in the metro resolver config, do we support them ?
//(...)
resolver: {extraNodeModules: {'@assets': path.resolve(__dirname,'src/assets')}}//(...)
What does this PR do?
Adds support for resolving aliased local SVG imports during Session Replay asset discovery.
Supports TypeScript/JavaScript path mappings and babel-plugin-module-resolver, including .babelrc, function-form plugin configurations, and Windows paths. Includes regression coverage for the supported configurations.
Before

After

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)