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

TypeError: Cannot assign to read only property '__typename' of object #4889

Open
hinogi opened this issue Oct 14, 2024 · 5 comments
Open

TypeError: Cannot assign to read only property '__typename' of object #4889

hinogi opened this issue Oct 14, 2024 · 5 comments
Labels
🐛 bug Unintended behavior

Comments

@hinogi
Copy link
Contributor

hinogi commented Oct 14, 2024

It seems there is an issue here where some properties are readonly because it seems to be another proxy object. This results in unexpected error messages when simply assigning values to initalValues because it seems to try to reassign proxied properties which are writable: false.

originalInitialValues.value = merge(deepCopy(originalInitialValues.value) || {}, deepCopy(values));

@hinogi
Copy link
Contributor Author

hinogi commented Oct 14, 2024

One strategy currently for me is to use structuredClone on the value before assigning them to initalValues

let initialValues = {};
initialValues.a = structuredClone(something.maybeproxy)

resetForm({ values: initalValues })

@logaretm
Copy link
Owner

Where did that state originate form? Vue-apollo?

@hinogi
Copy link
Contributor Author

hinogi commented Oct 19, 2024

Yes, forwarded via props.

@sschneider-ihre-pvs
Copy link

it happens with nested proxies.
For example if you have a structure that looks like

const result = {
  __typename: 'a',
  aType: 'string'
  b: {
    __typename: 'b',
    bType: 'string'
  }
}

in this case result is writable: true, configurable: true, but b is not, so when the attempt is made to merge result it will break at b because of that.

@logaretm
Copy link
Owner

logaretm commented Nov 7, 2024

I see, we can't use structuredClone because it will crash if someone has a computed or a ref inside their objects since it does not support proxies.

I will check if klona can be modified to not re-apply the same property descriptors as the original objects or not. I will mark this as a bug since we can definitely fix it without worrying about breaking behaviors.

Can you provide a quick reproduction of this so I can test against? it will make it much easier for me to work on a fix.

@logaretm logaretm added the 🐛 bug Unintended behavior label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants