Generate RCTThirdPartyComponents.mm with platform-specific macros #50637
+407
−10
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.
Summary:
iOS crashes in the New Architecture because Codegen includes all installed packages — even ones that don’t support iOS. The Legacy Architecture uses a different code generator that doesn’t have this issue. In both architectures, CocoaPods correctly excludes platform-specific native code — but Codegen doesn’t respect those exclusions in the New Architecture.
To prevent this, a macro was originally introduced to guard Objective-C code in generated components:
→ #42047
However, that macro usage was inadvertently lost during a later refactor that moved the Codegen provider to a static template:
→ #47518
This PR restores those platform guard macros in
RCTThirdPartyComponentsProvider
, ensuring that unsupported packages do not cause runtime crashes on iOS:This issue was initially reported in react-native-tvos#889, where a developer's iOS app crashed after including a tvOS-only package. CocoaPods correctly excluded the code, but Codegen still attempted to register the component at runtime.
Changelog:
[iOS] [Fixed] - Reintroduce platform guard macros in RCTThirdPartyComponentsProvider to prevent crashes when including platform-specific packages in OOT apps.
Test Plan:
MyApp contains several React Native packages that do not support iOS. When running on an iOS device, the app crashes.
Reproduce the steps for crash:
❌ MyApp launches and crashes immediately.
Apply patch to fix:
git apply patches/* yarn ios -i
✅ MyApp launches and does not crash.
Related Issues:
#42047 (Macro introduced)
#47518 (Regression)
react-native-tvos/react-native-tvos#889 (Original crash report)
https://github.com/cgoldsby/RNTV-889 (RVTV example)