Closed Freddy03h closed 3 months ago
:warning: | Add or Reformat Version Info |
---|---|
:information_source: | We could not find or parse the version number of React Native in your issue report. Please use the template, and report your version including major, minor, and patch numbers - e.g. 0.70.2 |
It's only happen on the old Architecture (no issue with new arch) and with a style created with
Stylesheet.create
and given tostyle
prop directly, not in an array.
Just a heads up that we're currently hyperfocused on New Architecture, so we won't be able to fix this bug in the immediate future (a community PR is more than welcome though).
Is there a reason why you're not moving to the New Architecture @Freddy03h ?
I have multiple projects for my clients with different dependencies and react-native versions (from 0.71), so it's not always easy to migrate to new architecture, depending on specific native dep on the project.
But we found this bug while creating types for fontWeight
in rescript-react-native
https://github.com/rescript-react-native/rescript-react-native/pull/806
And since the type number are also added in the Typescript definition, it can happen to Typescript users too: https://github.com/facebook/react-native/blob/8f548be91c2e0ac10e61535154b9db19dad7f3b7/packages/react-native/Libraries/StyleSheet/StyleSheetTypes.js#L814
Also, because it's a weird case, it's not always easy to know why this error happened.
I would like to help but I have no native android skills, also I don't know why this error exist only with Stylesheet.create
because now it's supposed to be an identity function, right?
So the issue is:
java.lang.Double cannot be cast to java.lang.String
I believe we do some props pre-processing if you pass an array vs if you pass a single prop. In this case it being Double
cause the framework to fail.
I don't have time to debug this, but for folks interested in helping out, I would put a breakpoint here: https://github.com/facebook/react-native/blob/d1bf828398f81c8bef6537004547a52260af76b4/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagersPropertyCache.java#L106-L128
and investigate how the array/single-value codepath diverge. The fix is probably trivial
I am working on fixing this.
I believe we do some props pre-processing if you pass an array vs if you pass a single prop.
It's a little more vicious than this because direct inline style works well
In StyleSheet.js
we are doing Object.freeze()
for Dev Mode only. By removing Object.freeze
there this issue was resolved. But that code is just for Dev Mode.
@Freddy03h Can you confirm if this issue is coming on release builds as well?
For Dev Mode only we are making style object immutable. So Ideally this issue should not come in production.
I checked this on release build as well. It's working fine for me. The issue is only on DEV Mode
@cortinico Here are my findings Reason: This issue is coming because of we are sending fontWeight as number instead of string from JS to Android.
When we are creating styles using StyleSheet.create()
we are calling Object.freeze()
on that making styles completely immutable.
So when in node_modules/react-native/Libraries/Text/Text.js
we are trying to mutate fontWeight with its string conversion it's not get updated. The problem is not just with this props even textAlignVertical
props will also not get updated.
Why this is not happening in other cases?
node_modules/react-native/Libraries/StyleSheet/flattenStyle.js
so there wouldn't be any problem.Solution
fontweight
.Let me know what you think. I can raise the PR for same
@shubhamguptadream11 Effectively I can't reproduce the error on release mode, so it's dev mode only.
And your change https://github.com/facebook/react-native/pull/45299/files fix the issue, thank you!
@Freddy03h Thanks for checking this. This is not my PR: https://github.com/facebook/react-native/pull/45299/files (As per this PR we are actually doing one extra operation for each style object in release mode as well which will be redundant since issue is not on release mode. And if let's say we put a DEV mode check there then it doesn't make sense to do freeze in StyleSheet file).
So I am waiting for inputs from @cortinico.
And
freeze make sense while development we preventing user to modify style and I have added extra layer that also removed on release. that time it check if object is freeze than only its return new object
Share your suggestions into https://github.com/facebook/react-native/pull/45299/files PR @cortinico
Addressing in https://github.com/facebook/react-native/pull/45340
Addressing in #45340
FlowFixMe it is also there in your PR why you need it. i think its not proper solution of it. @cortinico i think now you have to raised a pr (Please read my 1st PR comments first and provide us feedback, why it's closed without any proper valid reason)
@javache you have to do changes in TextInput.js
related to styles changes
@javache you have to do changes in
TextInput.js
related to styles changes
This was done in https://github.com/facebook/react-native/pull/45348
remaining things from your PR, i have added inside https://github.com/facebook/react-native/pull/45932, could you please review it
@Freddy03h so this issue is only happening on which specific version of react native ? few people here in discussion saying that it only happening in dev mode
@mahishdino since 0.71.0 to the latest version available when I created this issue : 0.74.3, I didn't test it on newer version. And yes we discovered that it's only happens on dev mode !
remaining things from your PR, i have added inside #45932, could you please review it
Closing as the linked PR has been merged
Thank you! 😃
Description
fontWeight
accept number values since0.71
But there is an issue on Android on a specific case:
It's only happen on the old Architecture (no issue with new arch) and with a style created with
Stylesheet.create
and given tostyle
prop directly, not in an array.style from Stylesheet.create directly passed to style prop
style from Stylesheet.create given to style prop in an array
inline style
style not created with
Stylesheet.create
Steps to reproduce
npx react-native init
React Native Version
0.74.3
Affected Platforms
Runtime - Android
Output of
npx react-native info
Stacktrace or Logs
Reproducer
https://github.com/Freddy03h/react-native-font-weight-number-android-issue
Screenshots and Videos