fix: Avoid NSNull RCTConvert warning when clearing scope context - #6651
Open
antonis wants to merge 3 commits into
Open
fix: Avoid NSNull RCTConvert warning when clearing scope context#6651antonis wants to merge 3 commits into
antonis wants to merge 3 commits into
Conversation
On the New Architecture, clearing a scope context forwarded `null` through `setContext(key, null)`. RN's TurboModule interop runs `RCTConvert` on each argument by its declared ObjC type before the native method runs, so the nullable `NSDictionary` parameter logged `JSON value '<null>' of type NSNull cannot be converted to NSDictionary` on every init/reload. Add a dedicated native `removeContext` method (iOS + Android, old and new arch) and route context clears through it so `null` never crosses the bridge. Falls back to the legacy `setContext(key, null)` path when the native binary predates the method. Also coerce non-string `setTag` values to a string to avoid the analogous NSString warning. Fixes #6645 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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. |
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 be8efcf. Configure here.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
📲 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
iOS (new) Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 3b6e9f9+dirty | 3822.77 ms | 1208.00 ms | -2614.77 ms |
| 5a23c47+dirty | 3843.54 ms | 1226.05 ms | -2617.50 ms |
| 100ce80+dirty | 3843.57 ms | 1226.46 ms | -2617.12 ms |
| 0bd8916+dirty | 3816.17 ms | 1215.05 ms | -2601.12 ms |
| a0d8cf8+dirty | 3826.15 ms | 1213.12 ms | -2613.03 ms |
| 0a9e622+dirty | 3825.35 ms | 1219.04 ms | -2606.31 ms |
| 21a1e70+dirty | 3826.22 ms | 1217.74 ms | -2608.47 ms |
| 9ad4522+dirty | 3862.28 ms | 1226.27 ms | -2636.01 ms |
| 88735e9+dirty | 3837.80 ms | 1216.39 ms | -2621.41 ms |
| d0e3b3e+dirty | 3846.64 ms | 1226.27 ms | -2620.38 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 3b6e9f9+dirty | 5.15 MiB | 6.68 MiB | 1.53 MiB |
| 5a23c47+dirty | 4.98 MiB | 6.46 MiB | 1.49 MiB |
| 100ce80+dirty | 5.15 MiB | 6.67 MiB | 1.51 MiB |
| 0bd8916+dirty | 5.15 MiB | 6.69 MiB | 1.53 MiB |
| a0d8cf8+dirty | 5.15 MiB | 6.67 MiB | 1.51 MiB |
| 0a9e622+dirty | 4.98 MiB | 6.51 MiB | 1.53 MiB |
| 21a1e70+dirty | 4.98 MiB | 6.46 MiB | 1.49 MiB |
| 9ad4522+dirty | 4.98 MiB | 6.56 MiB | 1.58 MiB |
| 88735e9+dirty | 4.98 MiB | 6.46 MiB | 1.49 MiB |
| d0e3b3e+dirty | 4.98 MiB | 6.51 MiB | 1.53 MiB |
Contributor
Android (new) Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 15d4514+dirty | 413.63 ms | 449.62 ms | 35.99 ms |
| 26843eb+dirty | 442.02 ms | 506.29 ms | 64.27 ms |
| ca9d079+dirty | 460.67 ms | 512.54 ms | 51.87 ms |
| f9c1ed4+dirty | 520.57 ms | 594.84 ms | 74.27 ms |
| a0d8cf8+dirty | 533.71 ms | 564.25 ms | 30.54 ms |
| 20fbd51+dirty | 594.38 ms | 655.35 ms | 60.97 ms |
| 0b0f006+dirty | 446.31 ms | 458.31 ms | 12.00 ms |
| 1d3572b+dirty | 444.48 ms | 478.42 ms | 33.94 ms |
| 4953e94+dirty | 398.80 ms | 431.81 ms | 33.01 ms |
| 4e0b819+dirty | 599.31 ms | 654.31 ms | 55.00 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 15d4514+dirty | 48.30 MiB | 53.60 MiB | 5.30 MiB |
| 26843eb+dirty | 49.74 MiB | 55.26 MiB | 5.52 MiB |
| ca9d079+dirty | 48.30 MiB | 53.58 MiB | 5.28 MiB |
| f9c1ed4+dirty | 49.74 MiB | 54.86 MiB | 5.12 MiB |
| a0d8cf8+dirty | 48.30 MiB | 53.49 MiB | 5.19 MiB |
| 20fbd51+dirty | 49.74 MiB | 54.81 MiB | 5.07 MiB |
| 0b0f006+dirty | 49.74 MiB | 55.66 MiB | 5.91 MiB |
| 1d3572b+dirty | 49.74 MiB | 55.38 MiB | 5.63 MiB |
| 4953e94+dirty | 43.94 MiB | 48.94 MiB | 5.00 MiB |
| 4e0b819+dirty | 49.74 MiB | 54.81 MiB | 5.07 MiB |
antonis
marked this pull request as ready for review
September 1, 2026 14:59
Contributor
Android (legacy) Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 0b5120f+dirty | 503.22 ms | 538.60 ms | 35.38 ms |
| ad66da3+dirty | 468.46 ms | 533.56 ms | 65.10 ms |
| 8448c07+dirty | 422.88 ms | 471.22 ms | 48.34 ms |
| 9474ead+dirty | 411.45 ms | 446.80 ms | 35.35 ms |
| 890d145+dirty | 504.54 ms | 491.55 ms | -12.99 ms |
| 68ae91b+dirty | 416.44 ms | 477.56 ms | 61.12 ms |
| 3ce5254+dirty | 410.57 ms | 448.48 ms | 37.91 ms |
| acd838e+dirty | 422.63 ms | 462.39 ms | 39.76 ms |
| 7d8c8bd+dirty | 417.45 ms | 462.10 ms | 44.65 ms |
| a636fa4+dirty | 486.70 ms | 508.53 ms | 21.83 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 0b5120f+dirty | 48.30 MiB | 53.58 MiB | 5.28 MiB |
| ad66da3+dirty | 48.30 MiB | 53.49 MiB | 5.19 MiB |
| 8448c07+dirty | 49.74 MiB | 55.37 MiB | 5.63 MiB |
| 9474ead+dirty | 48.30 MiB | 53.61 MiB | 5.30 MiB |
| 890d145+dirty | 43.75 MiB | 48.14 MiB | 4.39 MiB |
| 68ae91b+dirty | 49.74 MiB | 54.79 MiB | 5.05 MiB |
| 3ce5254+dirty | 43.75 MiB | 48.12 MiB | 4.37 MiB |
| acd838e+dirty | 48.30 MiB | 53.60 MiB | 5.30 MiB |
| 7d8c8bd+dirty | 48.30 MiB | 53.54 MiB | 5.23 MiB |
| a636fa4+dirty | 49.74 MiB | 55.36 MiB | 5.62 MiB |
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
On the New Architecture, clearing a scope context forwarded
nullthrough the nativesetContext(key, null)method. RN's TurboModule interop (ObjCTurboModule::invokeObjCMethod) runsRCTConverton each argument by its declared ObjC type before the native method runs, so the (nullable)NSDictionaryparameter logged this on every init/reload:This PR adds a dedicated native
removeContext(key)method and routes context clears through it, sonullnever crosses the bridge:wrapper.ts):NATIVE.setContext(key, null)now callsRNSentry.removeContext(key), with atypeof … === 'function'guard that falls back to the legacysetContext(key, null)path when the native binary predates the method (JS-updated-without-rebuild).RNSentry.mm):removeContext→[scope removeContextForKey:key]— the same call the existingsetContext(nil)path already made.RNSentryModuleImpl+ new/old arch modules):removeContext→scope.removeContexts(key)— likewise identical to the existingsetContext(null)path.turboModuleContext.ts):removeContextadded toRNSENTRY_SKIPso the tracker never wraps it — required to preserve the existing no-recursion invariant (the internalturbo_modulecontext clear goes through this method).setTaghardening: non-string values are coerced to a string (JSON.stringify(value) ?? 'undefined'), avoiding the analogous… cannot be converted to NSStringwarning when a tag value isundefined. MirrorssetExtra.The native
removeContextis behavior-identical to the existingsetContext(null)native paths — it's a new entry point, not new native behavior. No public API change (internalNativeRNSentrySpec only; not in the API report).💡 Motivation and Context
A bare
Sentry.init({ dsn })on iOS with the New Architecture logged the warning above on every init and reload. Even though the parameter is nullable, RN's interop layer warns during argument conversion.Fixes #6645
💚 How did you test it?
Sentry.init({ dsn }): 2× warnings pre-fix → 0× post-fix.newarchandoldarchsource sets).setContext(key, null)callsremoveContext; stale-binary fallback tosetContext(key, null);setTagstring/undefined/number coercion. 130 tests pass; lint clean.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
#XXXXCHANGELOG placeholder with this PR number.🤖 Generated with Claude Code