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

Unexpected Object.freeze() - "TypeError: cannot add a new property, js engine: hermes" #5430

Closed
mark-c-hoffner opened this issue Nov 29, 2023 · 2 comments
Labels
Repro provided A reproduction with a snippet of code, snack or repo is provided

Comments

@mark-c-hoffner
Copy link

Description

Functions passed to runOnJS as the property of an object cause all other properties of that object to be frozen.

I did not expect those other properties to be frozen.

If this is intended behavior, a remark on the runOnJS docs would be helpful.

Steps to reproduce

  1. Given this:
  const anArray = [];

  const aFunction = (s) => {
      anArray.push(s);
  };

  const anObject = {
    anArray,
    aFunction,
  };
  1. This fails:
  const aWorklet = () => {
    'worklet';
    runOnJS(anObject.aFunction)('fails');
  };
  1. This succeeds:
  const aWorklet = () => {
    'worklet';
    runOnJS(aFunction)('succeeds');
  };

Snack or a link to a repository

https://github.com/mark-c-hoffner/reanimated-freeze-reproduction

Reanimated version

3.6.0

React Native version

0.72.7

Platforms

Android

JavaScript runtime

Hermes

Workflow

React Native

Architecture

Fabric (New Architecture)

Build type

None

Device

Real device

Device model

moto g(7) play - 9

Acknowledgements

Yes

@mark-c-hoffner mark-c-hoffner added the Needs review Issue is ready to be reviewed by a maintainer label Nov 29, 2023
@github-actions github-actions bot added Platform: Android This issue is specific to Android Repro provided A reproduction with a snippet of code, snack or repo is provided labels Nov 29, 2023
@tomekzaw tomekzaw removed Platform: Android This issue is specific to Android Needs review Issue is ready to be reviewed by a maintainer labels Nov 29, 2023
@tomekzaw
Copy link
Member

tomekzaw commented Nov 29, 2023

Hey @mark-c-hoffner, thanks for submitting this issue as well as providing a detailed description.

Yes, this is an intended behaviour, but this limitation does not only affect runOnJS.

For each variable foo that you pass to a worklet, we call Object.freeze(foo) – see the code and the comment here.

const foo = { bar: { baz: 7 } };

runOnUI(() => {
  'worklet';
  console.log(foo.bar.baz);
})();

We freeze objects to prevent users from modifying the original object after it was copied to a worklet. There is no reactivity here and it would lead to hard-to-debug issues.

foo.bar.baz = 42; // this change wouldn't be reflected in the worklet (use a shared value instead)

Thanks for your suggestion to better document this, maybe we'll mention it in the "Troubleshooting" section in our docs or find a way to display a better warning in dev mode instead of the generic one from Object.freeze, added a task in our backlog.

@mark-c-hoffner
Copy link
Author

Thank you @tomekzaw for the clarification on the scope of Object.freeze with worklets. I just discovered react-native-reanimated and have been marveling at how it brings threading capabilities into JS. It makes complete sense that there's locking steps to prevent chaos.

I love the idea of somehow replacing the generic warning from Object.freeze when trying to add properties to a reanimated frozen object.

pafry7 added a commit to pafry7/react-native-bottom-sheet that referenced this issue May 28, 2024
pafry7 added a commit to pafry7/react-native-bottom-sheet that referenced this issue May 28, 2024
gorhom pushed a commit to gorhom/react-native-bottom-sheet that referenced this issue Jul 28, 2024
github-merge-queue bot pushed a commit to valora-inc/wallet that referenced this issue Aug 9, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@gorhom/bottom-sheet](https://ui.gorhom.dev/components/bottom-sheet)
([source](https://togithub.com/gorhom/react-native-bottom-sheet)) |
[`^4.6.3` ->
`^4.6.4`](https://renovatebot.com/diffs/npm/@gorhom%2fbottom-sheet/4.6.3/4.6.4)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@gorhom%2fbottom-sheet/4.6.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@gorhom%2fbottom-sheet/4.6.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@gorhom%2fbottom-sheet/4.6.3/4.6.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@gorhom%2fbottom-sheet/4.6.3/4.6.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>gorhom/react-native-bottom-sheet
(@&#8203;gorhom/bottom-sheet)</summary>

###
[`v4.6.4`](https://togithub.com/gorhom/react-native-bottom-sheet/blob/HEAD/CHANGELOG.md#464-2024-07-29)

[Compare
Source](https://togithub.com/gorhom/react-native-bottom-sheet/compare/v4.6.3...v4.6.4)

##### Bug Fixes

- add missing rest props to backdrop component
([#&#8203;1895](https://togithub.com/gorhom/react-native-bottom-sheet/issues/1895))(by
[@&#8203;hraschan](https://togithub.com/hraschan))
([6b99810](https://togithub.com/gorhom/react-native-bottom-sheet/commit/6b99810cb9f3a9b11159c27737ef7e4355b105b3))
- assigning to read-only property 'reduceMotion'
([#&#8203;1848](https://togithub.com/gorhom/react-native-bottom-sheet/issues/1848))(by
[@&#8203;pafry7](https://togithub.com/pafry7))
([efd4e92](https://togithub.com/gorhom/react-native-bottom-sheet/commit/efd4e92b647825aeaf5ca983e43d1a21d620ecfe)),
closes
[/github.com/software-mansion/react-native-reanimated/issues/5430#issuecomment-1831453991](https://togithub.com//github.com/software-mansion/react-native-reanimated/issues/5430/issues/issuecomment-1831453991)
- replace getRefNativeTag with findNodeHandle
([#&#8203;1823](https://togithub.com/gorhom/react-native-bottom-sheet/issues/1823))(by
[@&#8203;AndreiCalazans](https://togithub.com/AndreiCalazans))
([b906f5e](https://togithub.com/gorhom/react-native-bottom-sheet/commit/b906f5e67afdb823b7c31a9a929e757fc35222a2))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 5pm,every weekend" in timezone
America/Los_Angeles, Automerge - "after 5pm,every weekend" in timezone
America/Los_Angeles.

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View the
[repository job
log](https://developer.mend.io/github/valora-inc/wallet).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4yMC4xIiwidXBkYXRlZEluVmVyIjoiMzguMjAuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsibnBtIiwicmVub3ZhdGUiXX0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Repro provided A reproduction with a snippet of code, snack or repo is provided
Projects
None yet
Development

No branches or pull requests

2 participants