Cannot add new property '__reanimatedHostObjectRef'
See original GitHub issueDescription
I can’t use an array of objects coming in through a prop inside worklets. A prop with a simple value like a number works fine. Also making a deep copy with JSON.parse(JSON.stringify(props.items))
solves the problem.
Looks like Reanimated tries to add a property on an immutable prop object and fails.
Steps to reproduce
type Props = {
items: Item[]
}
const MyComponent = ({ items }: Props) => {
const foo = () => {
'worklet'
const item = items[0] // <-- this line causes the error
}
return ...
}
Expected behavior
I should be able to use any type of props in worklets
Actual behavior
Cannot add new property '__reanimatedHostObjectRef'
Package versions
- React Native: 0.64.rc-0
- React Native Reanimated: installed from https://github.com/software-mansion/react-native-reanimated/pull/1469
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:18 (3 by maintainers)
Top Results From Across the Web
Cannot add new property '__reanimatedHostObjectRef' React ...
I am developing a project where I have a listiview and showing 150-200 customers. There is a feature where I need to drag...
Read more >runOnJS | React Native Reanimated - Software Mansion
runOnJS returns a function which can be safely run from the UI thread. Example. Here is an example of calling a javascript callback...
Read more >Cannot add property <propName>, object is not extensible
So I was referencing an object that didn't exist anymore and there was some kind of grab the reference before the old one...
Read more >cannot add property 1 object is not extensible - You.com
defineProperty () throws when adding a new property to a non-extensible object. To fix this error, you will either need to remove the...
Read more >Realm: Create reactive mobile apps in a fraction of the time
Change directories into the new project ( cd <project-name> ) and add the realm ... a property from an owning object and they...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had the same issue when trying to assign an object or array of objects from Redux state to a shared value.
e.g. using Redux Toolkit(RTK):
I tried using mock data and it worked just fine. It only throws error when trying to assign value returned from RTK’s selector. While trying to figure out where the problem is coming from, I found this:
When an object is assigned to a shared value, that object gets mutated by
reanimated
and a property called__reanimatedHostObjRef
gets added. Same for array of objects, every object in the array gets that property after it is assigned to shared value. And looks like it’s being added by this function: https://github.com/software-mansion/react-native-reanimated/blob/45c57a906b1c3881c37f08b09749a9c68faf7ce1/Common/cpp/SharedItems/ShareableValue.cpp#L21-L34 I’m assuming that it’s throwing the error because it failed to mutate the object, i.e. failed to add__reanimatedHostObjRef
property.But why this issue only occurs when trying to assign data returned from RTK? I think it’s because RTK uses
immer
internally, which is used to freeze the data. And this is related to https://github.com/software-mansion/react-native-reanimated/issues/1517#issuecomment-1041810730, where it throws the same error when trying to play around with frozen object.Probably that’s why the solution of deep copying the object/array of objects using
JSON.parse(JSON.stringify(items))
works. I think it would be better to show more readable error message if this issue doesn’t get resolved anytime soon.Dude, you’re so cool