react / react/react-native

RCTUnsafeExecuteOnMainQueueSync crash

Open
#47,645 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Author Provided Repro
Dominant language
C++
Stars
127k
Forks
25.3k
Avg merge
1d 23h
Merged PRs (30d)
4

Description

Description

UIKit's UIView only guarantee to run on main thread/MainActor.
But ReactNative's RCTRootView is expecting to run on main queue.
This will cause crash when using RCTRootView in UICollectionViewCell which may call init on com.apple.uikit.datasource.diffing (serial) queue.

Steps to reproduce

Init a RCTRootView in a UICollectionViewCell.init method

React Native Version

0.76.2

Affected Platforms

Runtime - iOS

Output of npx react-native info
System:
  OS: macOS 15.1
  CPU: (10) arm64 Apple M2 Pro
  Memory: 193.73 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 23.2.0
    path: /opt/homebrew/bin/node
  Yarn:
    version: 1.22.22
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.9.0
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2024.11.11.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/kyle/.rbenv/shims/pod
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: Not Found
  Ruby:
    version: 3.3.0
    path: /Users/kyle/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.2
    wanted: 0.76.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true
Stacktrace or Logs
- dataSource.apply(_:to:animatingDifferences:) (in main queue & MainThread)
- __UIDiffableDataSource _performOnApplyQueue: use dispatch_sync(diffQueue)
- ...
- RCTRootView init (in diffQueue & MainThread)
- RCTUnsafeExecuteOnMainQueueSync (crash)
Reproducer

https://github.com/Kyle-Ye/RNMainQueueCrashDemo

Screenshots and Videos
image
Other information

The original discussion can be found at here

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked RNMainQueueCrashDemo and trace RCTRootView initialization through RCTUnsafeExecuteOnMainQueueSync. Reproduce the UICollectionViewCell.init scenario during diffable data source application and compare it with the reported stack trace. Done means the crash no longer occurs in this initialization path.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, react
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.