Skip to content

fix(core): Preserve Metro config object identity in serializer wrapper#6188

Merged
antonis merged 2 commits into
mainfrom
antonis/fix-metro-serializer-object-identity
May 20, 2026
Merged

fix(core): Preserve Metro config object identity in serializer wrapper#6188
antonis merged 2 commits into
mainfrom
antonis/fix-metro-serializer-object-identity

Conversation

@antonis
Copy link
Copy Markdown
Contributor

@antonis antonis commented May 19, 2026

📢 Type of change

  • Bugfix

📜 Description

withSentryOptionsFromFile was creating a new config object via object spread when wrapping the Metro serializer. This broke object identity: Expo's serializer holds a closure over the original config object and reads config.serializer.getModulesRunBeforeMainModule at serialization time. Because the spread created a new serializer object, any downstream mutations to it (e.g. from react-native-worklets' getBundleModeMetroConfig) were invisible to Expo's closure.

The fix mutates config.serializer.customSerializer in place and preserves Expo's __originalSerializer marker on the wrapper function.

💡 Motivation and Context

Fixes #6151

When using @sentry/react-native with react-native-worklets in bundleMode, production builds (expo export / EAS Build) crash with:

Cannot read property 'code' of undefined

This happens because the worklet runtime entry module is dropped from the bundle. The getModulesRunBeforeMainModule entries added by react-native-worklets are written to the new config's serializer object, but Expo's serializer reads from the original one where those entries don't exist.

💚 How did you test it?

  • Reproduced the issue with a minimal Expo project using getSentryExpoConfig + getBundleModeMetroConfig + react-native-keyboard-controller
  • Verified via expo export bundle output:
    • Without fix: __r(4); __r(541); __r(2); __r(0); (worklet runtime entry missing)
    • With fix: __r(1705); __r(4); __r(541); __r(2); __r(0); (worklet runtime entry present)
  • Verified Release build on iOS simulator runs without crash
  • Added 3 new unit tests covering object identity preservation, __originalSerializer marker forwarding, and the no-marker case

📝 Checklist

  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • All tests passing
  • No breaking changes

🔮 Next steps

antonis and others added 2 commits May 19, 2026 15:05
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 19, 2026

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


  • fix(core): Preserve Metro config object identity in serializer wrapper by antonis in #6188
  • fix(core): Fix includeWebFeedback crash by stubbing browser wrapper modules by antonis in #6150
  • fix(core): Deduplicate native HTTP breadcrumbs by antonis in #6132
  • chore(deps): bump brace-expansion from 5.0.5 to 5.0.6 by dependabot in #6183
  • chore(deps): bump ws from 8.16.0 to 8.20.1 by dependabot in #6184
  • fix(ios): Use conditional import for SentrySwizzle.h by antonis in #6186
  • fix(ios): use framework-style import for SentrySwizzle.h by alwx in #6181
  • chore(deps): bump actions/create-github-app-token from 3.1.1 to 3.2.0 by dependabot in #6178
  • chore(deps): bump github/codeql-action from 4.35.4 to 4.35.5 by dependabot in #6176
  • chore(deps): bump getsentry/craft from 2.26.3 to 2.26.5 by dependabot in #6179
  • chore(deps): bump getsentry/craft/.github/workflows/changelog-preview.yml from 2.26.3 to 2.26.5 by dependabot in #6177
  • fix(core): Resolve expo CLI directly instead of using npx in sourcemap upload by antonis in #6155
  • feat(core): Surface textComponentNames option in Metro config by antonis in #6169
  • chore(deps): update Sentry Android Gradle Plugin to v6.7.0 by github-actions in #6153
  • Filter ExceptionsManager.reportException duplicates in app-start init by alwx in #6145
  • chore(deps): update JavaScript SDK to v10.53.1 by github-actions in #6139
  • feat(core): Enable autoInjectSentryLabel by default in Metro config by antonis in #6141
  • feat(core): Respect Mask boundaries when reading sentry-label by antonis in #6142
  • fix(android): Handle boolean values in JSON options converter by antonis in #6130
  • Multi-instance <TimeToInitialDisplay> / <TimeToFullDisplay> coordination; a multi-signal TTID/TTFD system by alwx in #6090
  • chore(deps): update Bundler Plugins to v5.3.0 by github-actions in #6138
  • chore: Merge 8.11.1 back to main by antonis in #6135
  • chore: Update warning regarding iOS crash in sentry-cocoa 9.12.0 by antonis in #6136
  • chore(deps): update CLI to v3.4.2 by github-actions in #6129

Plus 12 more


🤖 This preview updates automatically when you update the PR.

@antonis
Copy link
Copy Markdown
Contributor Author

antonis commented May 19, 2026

@sentry review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 be48b92. Configure here.

@antonis antonis added the ready-to-merge Triggers the full CI test suite label May 19, 2026
@sentry
Copy link
Copy Markdown

sentry Bot commented May 19, 2026

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
Sentry RN io.sentry.reactnative.sample 8.11.1 (88) Release

⚙️ sentry-react-native Build Distribution Settings

@github-actions
Copy link
Copy Markdown
Contributor

iOS (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 3817.57 ms 1213.35 ms -2604.22 ms
Size 5.15 MiB 6.68 MiB 1.53 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
71abba0+dirty 3821.93 ms 1202.81 ms -2619.12 ms
a5d243c+dirty 3842.35 ms 1214.29 ms -2628.06 ms
f3215d3+dirty 3842.73 ms 1219.33 ms -2623.40 ms
4e0ba9c+dirty 3839.22 ms 1221.06 ms -2618.16 ms
9210ae6+dirty 3815.93 ms 1214.14 ms -2601.79 ms
7ac3378+dirty 1213.37 ms 1218.15 ms 4.78 ms
4953e94+dirty 1212.06 ms 1214.83 ms 2.77 ms
2c735cc+dirty 1229.67 ms 1221.50 ms -8.17 ms
100ce80+dirty 3842.93 ms 1229.52 ms -2613.41 ms
4b87b12+dirty 1212.90 ms 1222.09 ms 9.19 ms

App size

Revision Plain With Sentry Diff
71abba0+dirty 5.15 MiB 6.67 MiB 1.52 MiB
a5d243c+dirty 5.15 MiB 6.68 MiB 1.53 MiB
f3215d3+dirty 5.15 MiB 6.67 MiB 1.52 MiB
4e0ba9c+dirty 5.15 MiB 6.67 MiB 1.51 MiB
9210ae6+dirty 5.15 MiB 6.68 MiB 1.53 MiB
7ac3378+dirty 3.38 MiB 4.76 MiB 1.38 MiB
4953e94+dirty 3.38 MiB 4.73 MiB 1.35 MiB
2c735cc+dirty 3.38 MiB 4.74 MiB 1.35 MiB
100ce80+dirty 5.15 MiB 6.67 MiB 1.51 MiB
4b87b12+dirty 3.38 MiB 4.77 MiB 1.39 MiB

@github-actions
Copy link
Copy Markdown
Contributor

iOS (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 3839.71 ms 1214.31 ms -2625.40 ms
Size 5.15 MiB 6.68 MiB 1.53 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
71abba0+dirty 3852.70 ms 1224.53 ms -2628.16 ms
a5d243c+dirty 3827.92 ms 1220.10 ms -2607.81 ms
f3215d3+dirty 3846.08 ms 1231.85 ms -2614.23 ms
4e0ba9c+dirty 3856.39 ms 1234.44 ms -2621.95 ms
9210ae6+dirty 3834.11 ms 1216.64 ms -2617.47 ms
7ac3378+dirty 1202.35 ms 1198.31 ms -4.04 ms
4953e94+dirty 1217.41 ms 1223.53 ms 6.12 ms
2c735cc+dirty 1223.33 ms 1224.38 ms 1.04 ms
100ce80+dirty 3843.57 ms 1226.46 ms -2617.12 ms
4b87b12+dirty 1199.49 ms 1199.78 ms 0.29 ms

App size

Revision Plain With Sentry Diff
71abba0+dirty 5.15 MiB 6.67 MiB 1.52 MiB
a5d243c+dirty 5.15 MiB 6.68 MiB 1.53 MiB
f3215d3+dirty 5.15 MiB 6.67 MiB 1.52 MiB
4e0ba9c+dirty 5.15 MiB 6.67 MiB 1.51 MiB
9210ae6+dirty 5.15 MiB 6.68 MiB 1.53 MiB
7ac3378+dirty 3.38 MiB 4.76 MiB 1.38 MiB
4953e94+dirty 3.38 MiB 4.73 MiB 1.35 MiB
2c735cc+dirty 3.38 MiB 4.74 MiB 1.35 MiB
100ce80+dirty 5.15 MiB 6.67 MiB 1.51 MiB
4b87b12+dirty 3.38 MiB 4.77 MiB 1.39 MiB

@github-actions
Copy link
Copy Markdown
Contributor

Android (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 503.52 ms 560.86 ms 57.34 ms
Size 48.30 MiB 53.54 MiB 5.24 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
4e0ba9c+dirty 421.39 ms 455.80 ms 34.41 ms
5748023+dirty 413.71 ms 468.71 ms 54.99 ms
100ce80+dirty 463.28 ms 532.10 ms 68.82 ms
71abba0+dirty 411.04 ms 453.67 ms 42.63 ms
7d8c8bd+dirty 406.06 ms 460.88 ms 54.81 ms
d2eadf8+dirty 468.02 ms 530.37 ms 62.35 ms
7d6fd3a+dirty 435.06 ms 458.78 ms 23.72 ms
3817909+dirty 357.52 ms 391.52 ms 34.00 ms
a0d8cf8+dirty 533.71 ms 564.25 ms 30.54 ms
d038a14+dirty 405.08 ms 444.36 ms 39.28 ms

App size

Revision Plain With Sentry Diff
4e0ba9c+dirty 48.30 MiB 53.49 MiB 5.19 MiB
5748023+dirty 48.30 MiB 53.54 MiB 5.23 MiB
100ce80+dirty 48.30 MiB 53.46 MiB 5.15 MiB
71abba0+dirty 48.30 MiB 53.49 MiB 5.19 MiB
7d8c8bd+dirty 48.30 MiB 53.54 MiB 5.23 MiB
d2eadf8+dirty 48.30 MiB 53.48 MiB 5.18 MiB
7d6fd3a+dirty 43.94 MiB 49.00 MiB 5.06 MiB
3817909+dirty 43.94 MiB 48.94 MiB 5.00 MiB
a0d8cf8+dirty 48.30 MiB 53.49 MiB 5.19 MiB
d038a14+dirty 48.30 MiB 53.49 MiB 5.19 MiB

@antonis antonis marked this pull request as ready for review May 19, 2026 14:14
@github-actions
Copy link
Copy Markdown
Contributor

Android (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 411.73 ms 450.06 ms 38.33 ms
Size 48.30 MiB 53.54 MiB 5.24 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
4e0ba9c+dirty 452.84 ms 473.36 ms 20.52 ms
3ce5254+dirty 410.57 ms 448.48 ms 37.91 ms
5748023+dirty 446.69 ms 505.63 ms 58.94 ms
8929511+dirty 405.33 ms 452.16 ms 46.83 ms
71abba0+dirty 496.54 ms 525.16 ms 28.63 ms
44c8b3f+dirty 414.20 ms 457.28 ms 43.08 ms
7d8c8bd+dirty 417.45 ms 462.10 ms 44.65 ms
4953e94+dirty 442.02 ms 456.52 ms 14.50 ms
d2eadf8+dirty 414.64 ms 454.56 ms 39.92 ms
0d9949d+dirty 403.57 ms 437.00 ms 33.43 ms

App size

Revision Plain With Sentry Diff
4e0ba9c+dirty 48.30 MiB 53.49 MiB 5.19 MiB
3ce5254+dirty 43.75 MiB 48.12 MiB 4.37 MiB
5748023+dirty 48.30 MiB 53.54 MiB 5.23 MiB
8929511+dirty 43.75 MiB 48.16 MiB 4.41 MiB
71abba0+dirty 48.30 MiB 53.49 MiB 5.19 MiB
44c8b3f+dirty 48.30 MiB 53.46 MiB 5.15 MiB
7d8c8bd+dirty 48.30 MiB 53.54 MiB 5.23 MiB
4953e94+dirty 43.75 MiB 48.08 MiB 4.33 MiB
d2eadf8+dirty 48.30 MiB 53.48 MiB 5.18 MiB
0d9949d+dirty 43.75 MiB 48.13 MiB 4.37 MiB

Copy link
Copy Markdown
Contributor

@alwx alwx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@antonis antonis merged commit 44cbae6 into main May 20, 2026
152 of 163 checks passed
@antonis antonis deleted the antonis/fix-metro-serializer-object-identity branch May 20, 2026 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Triggers the full CI test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash on production build when using bundleMode from react-native-worklets

2 participants