Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 of 6 tasks
kraenhansen opened this issue Aug 19, 2024 · 5 comments · Fixed by #2191
Closed
2 of 6 tasks
Labels
bug Something isn't working

Comments

@kraenhansen
Copy link
Contributor

kraenhansen commented Aug 19, 2024

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?

  • Android
  • iOS
  • macOS
  • visionOS
  • Windows

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

  • I agree to follow this project's Code of Conduct
@kraenhansen kraenhansen added the bug Something isn't working label Aug 19, 2024
@kraenhansen kraenhansen changed the title Callback passed to setImmediate is never called when React Native Callback passed to setImmediate is never called when React Native (new arch only) Aug 19, 2024
@tido64
Copy link
Member

tido64 commented Aug 19, 2024

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
Copy link
Contributor Author

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
Copy link
Member

tido64 commented Aug 19, 2024

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
Copy link
Contributor Author

kraenhansen commented Aug 19, 2024

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

@tido64 tido64 linked a pull request Aug 20, 2024 that will close this issue
1 task
@tido64
Copy link
Member

tido64 commented Aug 20, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants