rescript-react-native icon indicating copy to clipboard operation
rescript-react-native copied to clipboard

Fix fontWeight again

Open cknitt opened this issue 2 years ago • 4 comments

Fixes #775 again by reverting the fontWeight type definition to its pre-#793 state.

Unfortunately this is a breaking change yet again. But better than crashes on Android...

cknitt avatar Mar 04 '24 11:03 cknitt

@cknitt which version of react-native are you using?

Number values are accepted since 0.71 : https://github.com/facebook/react-native/pull/34598

I didn't experience any crash on Android or iOS.

Freddy03h avatar Mar 07 '24 08:03 Freddy03h

That's weird as I had the crash on Android with 0.73.5.

cknitt avatar Mar 07 '24 09:03 cknitt

I'm still on 0.71.14 so maybe there is a regression on this in [email protected] but it's seems that those modifications and the tests still exists on main branch… so I don't know ^^'

Freddy03h avatar Mar 07 '24 09:03 Freddy03h

I tested it on a 0.73.4 project and it work well on Android, without crashing.

Freddy03h avatar Mar 07 '24 09:03 Freddy03h

Sorry, patched this in the project I was working on at the time and then lost track of it.

Now a colleague has encountered the same problem in another project with RN 0.74.2. So this is definitely still an issue. Will merge now.

cknitt avatar Jul 01 '24 11:07 cknitt

I still not experienced the issue since 0.71

Are you using a custom font?

Are you using the new architecture?

Freddy03h avatar Jul 01 '24 16:07 Freddy03h

@cknitt Hi!

  • I tried using number on a 0.74 project and it doesn't crash on android.
  • I also never experienced a crash linked to this issue on my project with 25k users/day and a variety of android versions and configuration.
  • Tests with numbers existing on the react-native project.
  • I don't find any related issues on the RN project.

It's seems to be definitively an issue… but only on your project? Can you repro the issue outside?

This type was change 1 year ago, no one else seems to experienced the issue since, and I'm worried the revert to the old type will annoy people…

Freddy03h avatar Jul 03 '24 09:07 Freddy03h

This is not specific to a particular project of ours. My colleague encountered the issue in a new project, not in the one where I originally experienced it.

I will try to create a repo with a simple reproduction.

cknitt avatar Jul 03 '24 10:07 cknitt

@Freddy03h Ok, here is a simple repro:

  1. Create a new RN project with npx react-native init.
  2. Run the Android project.
  3. At the bottom of App.tsx, in the highlight style, change fontWeight from '700' to 700.

The problem does not occur for the other styles in that file. Maybe it is because the highlight style is applied on a nested <Text>.

Screenshot_1720004134

cknitt avatar Jul 03 '24 10:07 cknitt

@cknitt Hi! Thank you for all the informations! I opened an issue an the react-native repo https://github.com/facebook/react-native/issues/45285 and the error only happen in Dev mode with the use of Stylesheet.create and without the use of an array in the style prop.

I never experienced the issue on my project because now with dynamic style (dark/light mode) there's always a variable color to dynamically pass to the style prop in an array.

And because the error is not effective on Release mode, I never saw it on crashlytics (even with 2 text in my entire app where the issue should happen).

It's possible to create a patch-package with this tiny fix that will be fixed soon I hope : https://github.com/facebook/react-native/pull/45299/files

So, what's your opinion about reverting the type to the polymorphic variant? I think it would be nice not to have to rewrite the type for everyone for an issue that happen only in Dev mode in the old architecture.

Thank you.

Freddy03h avatar Jul 05 '24 15:07 Freddy03h

Hi @Freddy03h! Thank you very much for opening the issue on the React Native repo to get to the bottom of this.

It's possible to create a patch-package with this tiny fix that will be fixed soon I hope : https://github.com/facebook/react-native/pull/45299/files

I can confirm that this fixes the issue. This solution is fine with me, I'll make a PR to revert the type to the polymorphic variant.

cknitt avatar Jul 06 '24 13:07 cknitt