fix(core): Resolve Metro from project root for source map generation - #6625
Open
antonis wants to merge 5 commits into
Open
fix(core): Resolve Metro from project root for source map generation#6625antonis wants to merge 5 commits into
antonis wants to merge 5 commits into
Conversation
The vendored default serializer required Metro internals resolvable from the SDK's own location. In this monorepo the core package has its own Metro dev dependency (0.84.4) that shadows the app's Metro, so bundling the RN 0.87 sample generated source maps with the mismatched older Metro and threw `Unexpected module with full source map found` on the metro-runtime require.js polyfill. Resolve Metro internals from `options.projectRoot` (the app being bundled) with a fallback to the previous SDK-local resolution. In a normal install both resolve the same Metro instance, so behavior is unchanged; in the monorepo the sample now bundles with its own 0.87 Metro. Resolution is deferred to the first serialization so `options.projectRoot` is available, and memoized thereafter. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
antonis
force-pushed
the
fix/metro-resolve-project-root
branch
from
August 27, 2026 11:21
d8893b4 to
addbd1d
Compare
Contributor
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog.
🤖 This preview updates automatically when you update the PR. |
11 tasks
📲 Install BuildsAndroid
|
Contributor
iOS (legacy) Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| ecf47a2+dirty | 3835.20 ms | 1222.43 ms | -2612.77 ms |
| 3817909+dirty | 1183.90 ms | 1187.50 ms | 3.60 ms |
| 5ee78d6+dirty | 3847.52 ms | 1224.27 ms | -2623.25 ms |
| 890d145+dirty | 1223.59 ms | 1231.37 ms | 7.78 ms |
| e763471+dirty | 3841.16 ms | 1218.06 ms | -2623.09 ms |
| 3d31fcf+dirty | 3838.09 ms | 1223.46 ms | -2614.63 ms |
| 9210ae6+dirty | 3815.93 ms | 1214.14 ms | -2601.79 ms |
| 26843eb+dirty | 3861.60 ms | 1238.77 ms | -2622.82 ms |
| 7a89652+dirty | 3861.46 ms | 1229.61 ms | -2631.85 ms |
| 9ad4522+dirty | 3850.40 ms | 1222.40 ms | -2628.00 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| ecf47a2+dirty | 4.98 MiB | 6.46 MiB | 1.49 MiB |
| 3817909+dirty | 3.38 MiB | 4.73 MiB | 1.35 MiB |
| 5ee78d6+dirty | 5.15 MiB | 6.69 MiB | 1.53 MiB |
| 890d145+dirty | 3.38 MiB | 4.77 MiB | 1.38 MiB |
| e763471+dirty | 4.98 MiB | 6.51 MiB | 1.53 MiB |
| 3d31fcf+dirty | 4.98 MiB | 6.56 MiB | 1.58 MiB |
| 9210ae6+dirty | 5.15 MiB | 6.68 MiB | 1.53 MiB |
| 26843eb+dirty | 4.98 MiB | 6.53 MiB | 1.55 MiB |
| 7a89652+dirty | 5.15 MiB | 6.70 MiB | 1.55 MiB |
| 9ad4522+dirty | 4.98 MiB | 6.56 MiB | 1.58 MiB |
Contributor
Android (legacy) Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 8e18f68+dirty | 426.20 ms | 456.44 ms | 30.24 ms |
| 038a6d7+dirty | 524.82 ms | 531.92 ms | 7.10 ms |
| a858ac3+dirty | 426.50 ms | 484.82 ms | 58.32 ms |
| 822d35b+dirty | 429.31 ms | 498.04 ms | 68.73 ms |
| 5ca03f9+dirty | 423.30 ms | 467.00 ms | 43.70 ms |
| 083e3ef+dirty | 446.67 ms | 491.68 ms | 45.01 ms |
| 4953e94+dirty | 442.02 ms | 456.52 ms | 14.50 ms |
| 244f6e8+dirty | 424.36 ms | 488.29 ms | 63.92 ms |
| 2e64504+dirty | 450.52 ms | 482.70 ms | 32.18 ms |
| a9df5ce+dirty | 418.40 ms | 452.38 ms | 33.98 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 8e18f68+dirty | 49.74 MiB | 55.45 MiB | 5.71 MiB |
| 038a6d7+dirty | 48.30 MiB | 53.60 MiB | 5.30 MiB |
| a858ac3+dirty | 49.74 MiB | 55.08 MiB | 5.34 MiB |
| 822d35b+dirty | 49.74 MiB | 54.84 MiB | 5.10 MiB |
| 5ca03f9+dirty | 49.74 MiB | 55.26 MiB | 5.52 MiB |
| 083e3ef+dirty | 49.74 MiB | 55.36 MiB | 5.61 MiB |
| 4953e94+dirty | 43.75 MiB | 48.08 MiB | 4.33 MiB |
| 244f6e8+dirty | 49.74 MiB | 55.38 MiB | 5.63 MiB |
| 2e64504+dirty | 49.74 MiB | 55.45 MiB | 5.71 MiB |
| a9df5ce+dirty | 49.74 MiB | 55.36 MiB | 5.62 MiB |
Contributor
iOS (new) Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 3ce5254+dirty | 1217.70 ms | 1224.69 ms | 6.99 ms |
| 0b1b5e3+dirty | 3820.72 ms | 1207.94 ms | -2612.78 ms |
| 44abcc2+dirty | 3841.42 ms | 1214.77 ms | -2626.65 ms |
| 1d3572b+dirty | 3830.71 ms | 1222.23 ms | -2608.49 ms |
| 6177334+dirty | 3851.52 ms | 1226.23 ms | -2625.29 ms |
| 5ee78d6+dirty | 3815.71 ms | 1217.04 ms | -2598.67 ms |
| 083e3ef+dirty | 3871.96 ms | 1234.95 ms | -2637.01 ms |
| ce7b368+dirty | 3851.41 ms | 1222.37 ms | -2629.04 ms |
| 7887847+dirty | 3844.89 ms | 1221.67 ms | -2623.22 ms |
| 1122a96+dirty | 3839.17 ms | 1219.23 ms | -2619.93 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 3ce5254+dirty | 3.38 MiB | 4.76 MiB | 1.38 MiB |
| 0b1b5e3+dirty | 5.15 MiB | 6.70 MiB | 1.54 MiB |
| 44abcc2+dirty | 4.98 MiB | 6.55 MiB | 1.57 MiB |
| 1d3572b+dirty | 4.98 MiB | 6.56 MiB | 1.58 MiB |
| 6177334+dirty | 5.15 MiB | 6.68 MiB | 1.53 MiB |
| 5ee78d6+dirty | 5.15 MiB | 6.69 MiB | 1.53 MiB |
| 083e3ef+dirty | 4.98 MiB | 6.55 MiB | 1.57 MiB |
| ce7b368+dirty | 4.98 MiB | 6.51 MiB | 1.53 MiB |
| 7887847+dirty | 4.98 MiB | 6.46 MiB | 1.48 MiB |
| 1122a96+dirty | 5.15 MiB | 6.68 MiB | 1.53 MiB |
… over a nested SDK copy requireMetroModule now tries each candidate path shape against the app (projectRoot) before the SDK's own location, so the app's Metro wins even when the two copies expose internals via different subpaths (app on metro/src/*, SDK on metro/private/*). Adds projectRoot-preference and ordering-regression tests using on-disk fake-Metro fixtures. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Android (new) Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 8e18f68+dirty | 443.14 ms | 446.98 ms | 3.84 ms |
| ca9d079+dirty | 460.67 ms | 512.54 ms | 51.87 ms |
| c151573+dirty | 485.39 ms | 495.18 ms | 9.79 ms |
| 5a21b51+dirty | 505.16 ms | 539.20 ms | 34.04 ms |
| ecf47a2+dirty | 457.21 ms | 498.10 ms | 40.89 ms |
| 1d3572b+dirty | 444.48 ms | 478.42 ms | 33.94 ms |
| 3ce5254+dirty | 373.90 ms | 427.84 ms | 53.94 ms |
| 9b5615c+dirty | 428.67 ms | 490.15 ms | 61.48 ms |
| 2e64504+dirty | 488.33 ms | 541.31 ms | 52.98 ms |
| ad66da3+dirty | 411.49 ms | 449.38 ms | 37.89 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 8e18f68+dirty | 49.74 MiB | 55.45 MiB | 5.71 MiB |
| ca9d079+dirty | 48.30 MiB | 53.58 MiB | 5.28 MiB |
| c151573+dirty | 48.30 MiB | 53.54 MiB | 5.24 MiB |
| 5a21b51+dirty | 48.30 MiB | 53.49 MiB | 5.19 MiB |
| ecf47a2+dirty | 49.74 MiB | 54.82 MiB | 5.07 MiB |
| 1d3572b+dirty | 49.74 MiB | 55.38 MiB | 5.63 MiB |
| 3ce5254+dirty | 43.94 MiB | 48.98 MiB | 5.04 MiB |
| 9b5615c+dirty | 49.74 MiB | 55.09 MiB | 5.34 MiB |
| 2e64504+dirty | 49.74 MiB | 55.45 MiB | 5.71 MiB |
| ad66da3+dirty | 48.30 MiB | 53.49 MiB | 5.19 MiB |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 0645154. Configure here.
antonis
marked this pull request as ready for review
August 27, 2026 13:41
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.
📢 Type of change
📜 Description
The default Metro serializer resolved Metro's internal modules (
baseJSBundle,bundleToString,sourceMapString) from the SDK's own location (__dirname). In a workspace/monorepo where a different Metro version is nested under@sentry/react-nativethan the one the app uses, that meant source maps were generated with a mismatched Metro version.The serializer now resolves Metro internals preferring the app's
options.projectRoot, falling back to the SDK-resolvable Metro. Resolution is deferred to the first serialization (whenprojectRootis available) and memoized. In a normal single-Metro install both paths resolve to the same Metro, so behavior is unchanged.💡 Motivation and Context
Surfaced while bumping the React Native sample to 0.87 (Metro 0.87) while
packages/corepins Metro0.84.4as a devDependency: the nested SDK Metro shadowed the app's Metro 0.87 and broke production source-map generation. The fix also benefits real users who have multiple Metro versions resolvable in a monorepo.Split out of #6617 so the sample bump carries no core changes.
💚 How did you test it?
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
options.projectRootwhen a different Metro is nested under the SDK.🤖 Generated with Claude Code