microsoft / react-native-test-app

react-native-test-app provides an app for all supported platforms as a package
MIT License
586 stars 87 forks source link

Callback passed to `setImmediate` is never called when React Native (new arch only) #2189

Closed kraenhansen closed 3 weeks ago

kraenhansen commented 3 weeks ago

What happened?

Doing a clean init and calling setImmediate will never call the callback passed:

setTimeout(() => {
  console.log("setTimeout works"); // Is printed as expected
});
setImmediate(() => {
  console.log("setImmediate works"); // Is never printed
});

NOTE: This was discovered in an upgrade of RN from v0.74.2 to v0.75.1 and RNTA from v3.8.7 to v3.9.3. I haven't pinned if this is due to the upgrade of RN or RNTA. I've have however tried (and failed at) reproducing this with a bare React Native 0.75.1 app using the community CLI, which is why I report it here.

NOTE: I've tested on iOS - it might be an issue elsewhere too.

Version

18.3.1

What platforms are you seeing this issue on?

System Information

npx react-native info
info Fetching system and libraries information...
System:
  OS: macOS 14.6.1
  CPU: (14) arm64 Apple M3 Max
  Memory: 128.59 MB / 36.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.16.0
    path: ~/.local/state/fnm_multishells/50268_1724062098858/bin/node
  Yarn: Not Found
  npm:
    version: 10.8.1
    path: ~/.local/state/fnm_multishells/50268_1724062098858/bin/npm
  Watchman:
    version: 2024.07.15.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.4
      - iOS 17.4
      - macOS 14.4
      - tvOS 17.4
      - visionOS 1.1
      - watchOS 10.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.2 AI-232.10300.40.2321.11567975
  Xcode:
    version: 15.3/15E204a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.11
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.75.1
    wanted: 0.75.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: false
  newArchEnabled: true
iOS:
  hermesEnabled: false
  newArchEnabled: true

Steps to Reproduce

  1. Run npx --package react-native-test-app@latest init
  2. Run pod install with new arch enabled: RCT_NEW_ARCH_ENABLED=1 pod install --project-directory=ios
  3. Add calls to setTimeout and setImmediate as in the "What happened?" step to App.tsx
  4. Run the ios app: npm run ios
  5. Note how the "setTimeout" log is printed while the "setImmediate" is not
  6. (optionally) Disable new arch when running pod install, run again and note how the "setImmediate" message is logged as expected.

Code of Conduct

tido64 commented 3 weeks ago

Thanks for filing this! We missed a new addition (facebook::react::DefaultTurboModules) in 0.75. This should be handled by @rnx-kit/react-native-host and you can bump that package separately once a new version is published. We will of course also bump it in RNTA asap.

I would really appreciate it if you could verify it locally as well.

kraenhansen commented 3 weeks ago

For completeness did I succeed at reproducing this with react-native@0.74.2 and react-native-test-app@3.9.3. And since you're explicitly mentioning an addition in 0.75 I'm wondering how that might happen 🤔

I'll try reproducing the fix (with react-native@0.75.1) and report back.

tido64 commented 3 weeks ago

For completeness did I succeed at reproducing this with react-native@0.74.2 and react-native-test-app@3.9.3. And since you're explicitly mentioning an addition in 0.75 I'm wondering how that might happen 🤔

Interesting… I ran git diff 0.74-stable..0.75-stable -- packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm and this was the relevant diff:

@@ -214,7 +213,7 @@
 - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
                                                       jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
 {
-  return nullptr;
+  return facebook::react::DefaultTurboModules::getTurboModule(name, jsInvoker);
 }

 - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name

If this repros on 0.74, it means that the relevant native modules were registered a different way.

kraenhansen commented 3 weeks ago

I can confirm the proposed fix works locally with react-native@0.75.1, which unblocks me 🎉

tido64 commented 3 weeks ago

FYI, https://github.com/microsoft/react-native-test-app/releases/tag/3.9.5