Repository navigation
Description
Description
Selectively disabling autolinking of a native dependency with components registered in the codegen configuration in react-native.config.js causes builds to crash upon launch on iOS when the new architecture is enabled. This is because the generated RCTThirdPartyComponentsProvider.mm file contains references to the excluded library using NSClassFromString causing the returned NSDictionary from +[RCTThirdPartyComponentsProvider thirdPartyFabricComponents] to be populated with nil values since the classes are not bundled in the native build and therefore crashing the app. This has been confirmed in 0.78.2 and 0.79.2 but probably exists in 0.77.x as well.
Steps to reproduce
- Install a library that has the
componentProviderfield set in the codegen config (see reproducer) and install the iOS pods. - Build the app.
- App will crash with an exception (see in the stacktrace or logs section) even though it was built successfully.
React Native Version
0.79.2
Affected Platforms
Runtime - iOS
Output of npx @react-native-community/cli info
System:
OS: macOS 15.0.1
CPU: (10) arm64 Apple M1 Pro
Memory: 146.59 MB / 32.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 18.20.5
path: ~/.nvm/versions/node/v18.20.5/bin/node
Yarn:
version: 1.22.22
path: /opt/homebrew/bin/yarn
npm:
version: 10.8.2
path: ~/.nvm/versions/node/v18.20.5/bin/npm
Watchman: Not Found
Managers:
CocoaPods: Not Found
SDKs:
iOS SDK:
Platforms:
- DriverKit 24.0
- iOS 18.0
- macOS 15.0
- tvOS 18.0
- visionOS 2.0
- watchOS 11.0
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Xcode:
version: 16.0/16A242d
path: /usr/bin/xcodebuild
Languages:
Java:
version: 18.0.2.1
path: /usr/bin/javac
Ruby:
version: 2.7.5
path: ~/.rvm/rubies/ruby-2.7.5/bin/ruby
npmPackages:
"@react-native-community/cli":
installed: 18.0.0
wanted: 18.0.0
react:
installed: 19.0.0
wanted: 19.0.0
react-native:
installed: 0.79.2
wanted: 0.79.2
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: true
newArchEnabled: true
Stacktrace or Logs
{"arguments":["-[__NSPlaceholderDictionary initWithObjects:forKeys:count:]","8"],"format_string":"*** %s: attempt to insert nil object from objects[%lu]","name":"NSInvalidArgumentException","type":"objc-exception","composed_message":"*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[8]","class":"NSException"}
Last Exception Backtrace:
0 CoreFoundation 0x18ffcd2ec __exceptionPreprocess + 164
1 libobjc.A.dylib 0x18d451a7c objc_exception_throw + 88
2 CoreFoundation 0x18ff0160c -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 724
3 CoreFoundation 0x18ff0122c +[NSDictionary dictionaryWithObjects:forKeys:count:] + 52
4 XXX 0x1055e1b24 +[RCTThirdPartyComponentsProvider thirdPartyFabricComponents] + 912
5 XXX 0x10559fd24 __54-[RCTAppDependencyProvider thirdPartyFabricComponents]_block_invoke + 28
6 libdispatch.dylib 0x197e4b584 _dispatch_client_callout + 16
7 libdispatch.dylib 0x197e349a8 _dispatch_once_callout + 32
8 XXX 0x10559fd04 -[RCTAppDependencyProvider thirdPartyFabricComponents] + 124
9 XXX 0x105475bbc -[RCTDefaultReactNativeFactoryDelegate thirdPartyFabricComponents] + 64
10 XXX 0x105476548 -[RCTReactNativeFactory thirdPartyFabricComponents] + 84
11 XXX 0x1054b20d4 -[RCTComponentViewFactory registerComponentIfPossible:] + 308
12 XXX 0x1054b2a64
MANDATORY Reproducer
https://github.com/ismarbesic/react-native-codegen-selectively-disabled-lib-bug-repro
Screenshots and Videos
No response
Activity
cortinico commentedon May 6, 2025
cc @cipolleschi - Can you check if #51078 solves the issue correctly?
cipolleschi commentedon May 6, 2025
@ismarbesic thanks for opening the issue. I'll have a look at the fix shortly or tomorrow morning. Can I ask why do you need to turn off autolinking for that library? Is iOS not using it at all?
ismarbesic commentedon May 6, 2025
Thanks for checking it out! The library I added was just an example but we have similar internal use cases where we want to strip away certain libraries under certain conditions but still have functioning builds.
WheelerLee commentedon May 7, 2025
I have a similar issue. My dependencies look like this:
And the code is as follows:
Everything was working fine until I added my own specs and executed pod install.
The issue has been tested and occurs on React Native versions 0.77, 0.78, and 0.79, but version 0.76 works fine.
cipolleschi commentedon May 8, 2025
yeah, so the reason here is that, to maintain backward compatibility, we added a lookup mechanism that searches for the components. @WheelerLee Is your app crashing when opening the
RNSModalScreenor theRNScreen? The string after RNScreen is pretty wrong... it should just beRNSScreenView... 😓Exclude selectively disabled libraries from codegen generation (#51078)
ismarbesic commentedon May 8, 2025
@cipolleschi @cortinico I saw the PR was merged - thanks a lot for reviewing it! Glad we could contribute those changes back for everyone to benefit from.
Exclude selectively disabled libraries from codegen generation (#51078)
tux2nicolae commentedon Jun 22, 2025
We do have the same issue but in a different scenario, on IOS we have two targets, one is our full app and the other is an app clip, inside the app clip we should exclude some libraries to save space due to the size constraints.
For this to work we use this workaround.
This used to work until now, but now because of the auto discovery, the components will be found inside the appclip target as well and the app clip will crash, we did not found a solution to exclude some libraries from auto link inside a specific target, there is already a similar request which apparently did not get through
Exclude selectively disabled libraries from codegen generation (#51078)
Jigs6720 commentedon Jan 20, 2026
+1