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

Give more meaningful warning when modifying a Shareable

Open tjzel opened this issue 2 years ago • 1 comments

Summary

Wanted to open this PR for a long time.

Currently we use Object.freeze in development on objects after they were converted to a Shareable. This is problematic for users since there is no information about why is the object immutable all of a sudden.

While this PR won't give a meaningful error when user tries to add a new property to the object when doing something like:

const a = {};

function foo(){
'worklet';
console.log(a.b);
};

runOnUI(worklet)();
a.b = 1;
runOnUI(worklet)();

but it seems to be a rare case and mostly the problems are with modifying existing properties.

Test plan

const a = { b: 1 };
makeShareableCloneRecursive(a);
a.b = 2; // Warning here.

tjzel avatar Jan 02 '24 16:01 tjzel

@tomekzaw I moved docs and examples part to a separate PR #5560 after applying review suggestions

tjzel avatar Jan 05 '24 09:01 tjzel

@tomekzaw @tjzel this PR crashes our App (after upgrade to 3.12.0) . It crashes on launch with 'property is not configurable'. Any insights into debugging will be appreciated , it crashes at shareables.ts: 321 . https://github.com/software-mansion/react-native-reanimated/issues/6082

giantslogik avatar Jun 06 '24 09:06 giantslogik

@giantslogik It's fixed.

tjzel avatar Jun 10 '24 12:06 tjzel