reactotron icon indicating copy to clipboard operation
reactotron copied to clipboard

Can't push to arrays in `reactotron-core-client`

Open joshuayoes opened this issue 1 year ago • 4 comments

Error when using the latest beta release and upgrading React Native.

Screenshot 2023-04-20 at 4 41 27 PM

Steps to reproduce the issue.

  1. Checkout to https://github.com/infinitered/ignite/pull/2377
  2. Checkout to https://github.com/infinitered/reactotron/pull/1288
  3. Update this metro config in ignite/boilerplate/metro.config.jsScreenshot 2023-04-20 at 4 38 38 PM
  4. Run npx zx scripts/install-workspace-packages-in-target.mjs ~/Code/ignite/boilerplate/ from reactotron repo
  5. Run yarn start and yarn ios in ignite/boilerplate repo

Context

Tried getting around this by updating the property Screenshot 2023-04-20 at 4 46 20 PM

But this caused another issue where non-core plugins weren't getting initialized correctly like in reactotron-mst.

Seems like that mutating class properties causes some funky business with prototypes: https://stackoverflow.com/questions/57037585/why-we-cannot-add-a-new-property-to-an-object-constructor-the-same-way-we-add-a

joshuayoes avatar Apr 20 '23 23:04 joshuayoes

There seems to be one other stack overflow article with this exact error: https://stackoverflow.com/questions/74581572/pushing-an-object-to-an-array-react-native-firestore

joshuayoes avatar Apr 21 '23 00:04 joshuayoes

Tried pairing with ChatGPT on this, seems to be something about mutating references to properties in a class? https://sharegpt.com/c/rzXf15z

joshuayoes avatar Apr 21 '23 00:04 joshuayoes

So it turns out that Hermes cannot handle Javascript classes: Screenshot 2023-04-20 at 6 05 31 PM

joshuayoes avatar Apr 21 '23 01:04 joshuayoes

This seems to be handled by babel by metro-react-native-babel-preset

Babel does have a plugin to handle classes: https://github.com/facebook/metro/blob/ac3adced45a6ca32286dda9e9470eab6eb4218bf/packages/metro-react-native-babel-preset/src/configs/main.js#L76

Which appears to make properties read only: Playground Screenshot 2023-04-20 at 6 09 56 PM

But I fed this minified code into Hermes, and it seems to work 🤷 Screenshot 2023-04-20 at 6 08 51 PM

joshuayoes avatar Apr 21 '23 01:04 joshuayoes