Skip to content

Conversation

meetdhanani17
Copy link
Contributor

@meetdhanani17 meetdhanani17 commented Jul 5, 2024

Summary:

Fixes #45285
object created by StyleSheet.create provide readonly object and it cannot be changeable for farther value or type change according to native requirements, so I have added condition in flattenStyle function, if it's readonly than convert into editable object

Changelog:

[GENERAL] [FIXED] - fixed fontWeight number value error for android (java.lang.Double cannot be cast to java.lang. String)

@facebook-github-bot
Copy link
Contributor

Hi @meetdhanani17!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

Copy link

github-actions bot commented Jul 5, 2024

Warnings
⚠️ 📋 Missing Test Plan - Can you add a Test Plan? To do so, add a "## Test Plan" section to your PR description. A Test Plan lets us know how these changes were tested.

Generated by 🚫 dangerJS against d4d7e28

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Jul 5, 2024
@meetdhanani17 meetdhanani17 changed the title make readonly object editable for change style object attributes Make readonly object editable for change style object attributes Jul 6, 2024
@facebook-github-bot
Copy link
Contributor

@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@javache
Copy link
Member

javache commented Jul 8, 2024

This doesn't seem right to me. If the value we receive is frozen, we do not want to make an extra copy here for what will be a very common scenario.

This is a perf-sensitive code-path, let's be careful with changes here (eg with is the cost of calling isFrozen?)

@meetdhanani17
Copy link
Contributor Author

As you know about the styles it's doing frozen when enviroment is dev in ptoduction all the cost of reassign an object removed becuase we will not get frozon object that time, and when an object came in list then we are also regenerating an object, as it is development environment different it doesn't change in production/release

@meetdhanani17
Copy link
Contributor Author

For the preventing of style object attributes change by end development, i haven't removed freeze object return while style create using create method

@javache
Copy link
Member

javache commented Jul 8, 2024

It's not clear what this PR enables?

It is desirable for the output of flattenStyle to not be mutable and it shouldn't be assumed to be. flattenStyle is also an internal API that should not be called directly ideally.

@meetdhanani17
Copy link
Contributor Author

meetdhanani17 commented Jul 8, 2024

but this also make an array mutable that's what I want to tell you, and it is only occurs problem when we are try to change immutable change (but my question again is why we are try to change immutable object)

@meetdhanani17
Copy link
Contributor Author

It's not clear what this PR enables?

It is desirable for the output of flattenStyle to not be mutable and it shouldn't be assumed to be. flattenStyle is also an internal API that should not be called directly ideally.

flattenStyle after calling this function In text component we are change the font weight of this style, I can also apply solution for that component only but i was thinking like this is what kind of object if i pass array of immutable then its return mutable object and mutable object pass then also its return mutable object so there is no meaning to differentiate

@javache
Copy link
Member

javache commented Jul 9, 2024

my question again is why we are try to change immutable object

flattenStyle after calling this function In text component we are change the font weight of this style

We should address the root cause here, which does seem to be the text component, we shouldn't be mutating the return value of flattenStyle.

I'd recommend changing Text.js like this instead (the $FlowFixMe's there a clear sign the API boundary is not respected)

let processedStyle = flattenStyle(_style);
if (processedStyle != null) {
  let overrides = null;
  if (typeof processedStyle.fontWeight === 'number') {
    overrides = overrides || {};
    overrides.fontWeight = processedStyle.fontWeight.toString();
  }
  [...]
  if (overrides != null) {
    processedStyle = [processedStyle, overrides];
  }

@javache
Copy link
Member

javache commented Jul 9, 2024

I will send a PR for this.

@javache
Copy link
Member

javache commented Jul 9, 2024

#45340 addresses this issue.

@javache javache closed this Jul 9, 2024
@meetdhanani17
Copy link
Contributor Author

Ok great, but i'm am also working on native side for fix it

@meetdhanani17
Copy link
Contributor Author

meetdhanani17 commented Jul 9, 2024

I'd recommend changing Text.js like this instead (the $FlowFixMe's there a clear sign the API boundary is not respected)

That what i have talked with you, like i have multiple ways to solve this issue if you said to change only text file then i'll fix using only Text.js file and you can compare here i have removed FlowFixMe's while return mutable object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Android] fontWeight number value error if not in an array
3 participants