Skip to content

Disabling autolinking on iOS selectively in react-native.config.js crashes the app during runtime #51077

@ismarbesic

Description

@ismarbesic

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

  1. Install a library that has the componentProvider field set in the codegen config (see reproducer) and install the iOS pods.
  2. Build the app.
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions