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

Turbomodule method with Int32 param not bridged correctly #49688

Closed
wvanhaevre opened this issue Feb 26, 2025 · 4 comments
Closed

Turbomodule method with Int32 param not bridged correctly #49688

wvanhaevre opened this issue Feb 26, 2025 · 4 comments
Labels
Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Needs: Attention Issues where the author has responded to feedback. Newer Patch Available Resolution: PR Submitted A pull request with a fix has been provided. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@wvanhaevre
Copy link

Description

Passing an Int32 as a param to a Turbomodule will result in a wrong encoded NSInteger.

Given a basic spec for a simple TurboModule that takes an Int32 as parameter (from CodegenTypes):

import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';
import { Int32 } from 'react-native/Libraries/Types/CodegenTypes';

export interface Spec extends TurboModule {
  setMyInt32(value: Int32): void;
}

export default TurboModuleRegistry ? TurboModuleRegistry.getEnforcing<Spec>('TestModule') : undefined;

Codegen generates the following ObjC signature for that method:

- (void)setMyInt32:(NSInteger)value 

However in the ObjCTurboModule::setInvocationArg only a BOOL, double or NSNumber seems to be supported. The Int32 value is interpreted as a double and the output of an NSLog

- (void)setMyInt32:(NSInteger)value { 
    NSLog(@"My Int32 (ObjC): %ld", value);
}

is
My Int32 (ObjC): 4617315517961601024

Where invoking the turboModule on the Javascript side:

const myValue = 5;
console.log(`My Int32 (JS): ${myValue}`);
NativeTestModule.setMyInt32(myValue);

outputs:
My Int32 (JS): 5

It looks like ObjCInteropTurboModule is taking into account a wider set of param types.

Steps to reproduce

Using the snippets above a basic setup of a Turbomodule can be made
Calling NativeTestModule.setMyInt32(5);
Will result in a bridged output of
My Int32 (ObjC): 4617315517961601024

React Native Version

0.76.5

Affected Platforms

Runtime - iOS

Areas

TurboModule - The New Native Module System

Output of npx @react-native-community/cli info

System:
  OS: macOS 15.0.1
  CPU: (8) arm64 Apple M1 Pro
  Memory: 115.91 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.11.0
    path: ~/.nvm/versions/node/v22.11.0/bin/node
  Yarn:
    version: 1.22.22
    path: ~/.nvm/versions/node/v22.11.0/bin/yarn
  npm:
    version: 10.9.0
    path: ~/.nvm/versions/node/v22.11.0/bin/npm
  Watchman:
    version: 2024.08.19.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.2
      - iOS 18.2
      - macOS 15.2
      - tvOS 18.2
      - visionOS 2.2
      - watchOS 11.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2411.12169540
  Xcode:
    version: 16.2/16C5032a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.12
    path: /usr/bin/javac
  Ruby:
    version: 3.3.5
    path: /opt/homebrew/opt/ruby/bin/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: Not Found
  react-native-macos: Not Found
  react-native-tvos:
    installed: 0.76.5-0
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

My Int32 (JS): 5
My Int32 (ObjC): 4617315517961601024

Reproducer

https://github.com/THEOplayer/react-native-theoplayer/tree/bugfix/reproducer-turbomodule-int32

Screenshots and Videos

No response

@wvanhaevre wvanhaevre added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels Feb 26, 2025
@react-native-bot react-native-bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Newer Patch Available labels Feb 26, 2025
@react-native-bot
Copy link
Collaborator

Tip

Newer version available: You are on a supported minor version, but it looks like there's a newer patch available - 0.76.7. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@react-native-bot
Copy link
Collaborator

Warning

Missing reproducer: We could not detect a reproducible example in your issue report. Please provide either:

@react-native-bot
Copy link
Collaborator

Tip

Newer version available: You are on a supported minor version, but it looks like there's a newer patch available - undefined. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@wvanhaevre
Copy link
Author

wvanhaevre commented Feb 26, 2025

Above shared code reproduces the issue
This link to github points to a working app that reproduces the issue when pressing pause on the video.

JS part: link
ObjC part:link
CodeGen: link

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Feb 26, 2025
@migueldaipre migueldaipre added Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Resolution: PR Submitted A pull request with a fix has been provided. and removed Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Needs: Attention Issues where the author has responded to feedback. Newer Patch Available Resolution: PR Submitted A pull request with a fix has been provided. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants