react-native-worklets-core icon indicating copy to clipboard operation
react-native-worklets-core copied to clipboard

`Worklets.createSharedValue` can't set fields on an object value individually

Open caheinz2 opened this issue 1 year ago • 0 comments

I can't create a shared value that contains an object and then update the object's fields later. The get_set_object_value test in sharedvalue-tests.ts describes exactly what I am trying to do, and the test seems to be failing in release 1.2.0.

  get_set_object_value: () => {
    const sharedValue = Worklets.createSharedValue({ a: 100, b: 200 });
    sharedValue.value.a = 50;
    sharedValue.value.b = 100;
    return ExpectValue(sharedValue.value, { a: 50, b: 100 });
  },

The test output is:

 LOG  Running "WorkletsExample" with {"rootTag":11}
 LOG  Starting test with index 1
 LOG  Running test: get_set_object_value
 LOG  Loading react-native-worklets-core...
 LOG  Worklets loaded successfully
 LOG  ExpectValue, resolved: {"a": 100, "b": 200}
 LOG  ExpectValue, failed: Expected {"a":50,"b":100}, got {"a":100,"b":200}.
 LOG  Test: get_set_object_value failed.

I can only update the entire sharedValue like so:

  sharedValue.value = {
    a: 50,
    b: 100,
  };

I believe this is a regression of https://github.com/margelo/react-native-worklets-core/pull/178.

caheinz2 avatar May 02 '24 20:05 caheinz2