-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Using the spread operator on Native modules breaks compatibility layer for bridgeless mode #43221
Comments
Hi @gabrieldonadel, thanks for opening the issue. |
Yes that's correct, but it was probably only noticed now because bridgeless will be enabled by default |
The spread operator only copies the object's own enumerable properties, and since we use object prototypes now to lazily load turbomodule methods, this will no longer work. I suggest you use
|
I think that's not the only thing that causes this to fail, here is another example where this is a problem invertase/react-native-firebase#7688 |
|
Closing as per this reason. We won't be able to fix this |
Description
While investigating why the compatibility layer was not working for react-native-netinfo when bridgeless mode was tuned on, I noticed that they were using the spread operator (
...
) directly on the object returned from React Native'sNativeModules
e.g.This is not a problem when bridgeless mode is tuned off, but as soon as bridgeless mode is tuned on, trying to access any of the module functions will result in an unhandled promise rejection
Upon some investigation, I noticed that this same error also happens if we try to use the spread operator over a turbo module (with bridgeless mode on and off). I believe that's the case because the module object is a host object and doesn't quite support the
...
syntax yet.To fix this specific case I just used
Object.assign
instead (check react-native-netinfo/react-native-netinfo#717 for more details), but thinking from a compatibility perspective we should try to address this so that old/unmaintained libraries that use this pattern can benefit from the compatibility layerSteps to reproduce
With bridgeless mode ON:
Or just clone https://github.com/gabrieldonadel/rn-spread-operator-bug and run the app, it already includes all the use cases
React Native Version
0.74.0-rc.1
Affected Platforms
Runtime - Android, Runtime - iOS
Output of
npx react-native info
Stacktrace or Logs
Reproducer
https://github.com/gabrieldonadel/rn-spread-operator-bug
Screenshots and Videos
Screen.Recording.2024-02-27.at.21.45.57.mov
Screen.Recording.2024-02-27.at.21.44.31.mov
Screen.Recording.2024-02-27.at.21.43.08.mov
Screen.Recording.2024-02-27.at.21.41.17.mov
The text was updated successfully, but these errors were encountered: