question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot access `RuntimeExecutor` through `RCTCxxBridge` on iOS

See original GitHub issue

Description

It is currently not possible to access RuntimeExecutor through RCTCxxBridge on iOS even though it’s available through _reactInstance->getRuntimeExecutor():

@implementation RCTMyModule

@synthesize bridge = _bridge;

RCT_EXPORT_MODULE()

- (void)initialize {
  RCTCxxBridge *cxxBridge = (RCTCxxBridge *)_bridge;

  // Cannot access `RuntimeExecutor` through `cxxBridge`
}

@end

On Android, RuntimeExecutor can be accessed through CatalystInstance:

public class MyModule extends ReactContextBaseJavaModule {
  public MyModule(ReactApplicationContext reactContext) {
    super(reactContext);
  }

  public void initialize() {
    RuntimeExecutor runtimeExecutor = this
      .getReactApplicationContext()
      .getCatalystInstance()
      .getRuntimeExecutor();
  }
}

Should RCTCxxBridge expose the underlying Instance similar to how it’s done on Android or simply expose a runtimeExecutor getter?

I’m currently using a shim based on CallInvoker to work around this:

facebook::react::RuntimeExecutor runtimeExecutor =
  [cxxBridge](std::function<void(facebook::jsi::Runtime & runtime)> &&callback) {
    cxxBridge.jsCallInvoker->invokeAsync(
      [cxxBridge, callback = std::move(callback)]() {
        callback(*(facebook::jsi::Runtime *)(cxxBridge.runtime));
      }
    );
  };

Version

0.66.4

Output of npx react-native info

System: OS: macOS 11.6.2 CPU: (4) x64 Intel® Core™ i5-4308U CPU @ 2.80GHz Memory: 77.92 MB / 8.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 17.2.0 - /usr/local/bin/node Yarn: 1.22.17 - /usr/local/bin/yarn npm: 8.1.4 - /usr/local/bin/npm Watchman: 2021.12.06.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.2 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3 Android SDK: Not Found IDEs: Android Studio: 2020.3 AI-203.7717.56.2031.7784292 Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild Languages: Java: 17.0.1 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: ^17.0.2 => 17.0.2 react-native: ^0.66.4 => 0.66.4 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

  1. Create a native module for iOS.
  2. Access its associated RCTBridge and cast it to RCTCxxBridge.
  3. Notice how there’s no way to access the RuntimeExecutor hiding behind _reactInstance->getRuntimeExecutor().

Snack, code example, screenshot, or link to a repository

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kasperisagercommented, Jan 24, 2022

On a related note, I might be holding RuntimeExecutor wrong. I’m using it to install JSI bindings for a native module, but on Android, which uses _reactInstance->getRuntimeExecutor(), I’m not seeing the bindings in the JavaScript context of the application:

executeAsynchronously(runtimeExecutor, [](Runtime &runtime) {
  runtime.global().setProperty(
    runtime,
    "__myFunction",
    Function::createFromHostFunction(...)
  );
});

When the application loads, __myFunction is undefined. It works just fine on iOS with the RuntimeExecutor shim described previously.

Edit: The cause has been identified in https://github.com/facebook/react-native/issues/32813#issuecomment-1020021633.

0reactions
kasperisagercommented, Jun 23, 2022

Is there anything I can do to help this issue along?

Read more comments on GitHub >

github_iconTop Results From Across the Web

If your iPhone or iPad won't connect to a Wi-Fi network
If your device can connect, you need to get help with your Wi-Fi network. If your device can't connect to any Wi-Fi networks,...
Read more >
Updated React Native, can't find 'boost' dependency in ...
Open the <app_name>/ios/<app_name>.xcworkspace file in Xcode. Raise the iOS Deployment Target (in my case I only bumped to 10).
Read more >
cocoapods could not find compatible versions for pod "rct- ...
trying to upgrade to latest version to have access to RippleConfig.foreground in 0.66 but running into this issue on the ios side ...
Read more >
[Fixed]-React Native JSI: How to call expose a promised function ...
I want to implement it with React Native JSI so how to expose asynchronous ... PropNameID::forAscii(runtime, "executor"), 2, [strURL](Runtime &runtime, ...
Read more >
@react-native/assets | Yarn - Package Manager
React Native brings React's declarative UI framework to iOS and Android. With React Native, you use native UI controls and have full access...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found