realm-js: Realm + Reanimated v2 w/ JSC causes Realm to not work
Goals
Use react-native-reanimated v2 alongside Realm. Reanimated v2 used to require Hermes (and I’m aware RealmJS’s Hermes support is still WIP) but v2.2.0+ have added JSC support as well [1].
Expected Results
The two to live together happily.
Actual Results
In our instance - the app runs fine on iOS but on Android we can save stuff to Realm but reloading it results in objects being undefined. Others have reported app crashes with minimal repros to the renimated project already [2] but I thought I’d report it here too incase it can be fixed from the Realm side.
Steps to Reproduce
Install Realm + react-native-reanimated v2.2.0+ in the same app without Hermes - attempt to use Realm on Android.
Code Sample
See minimal repro on this ticket: https://github.com/software-mansion/react-native-reanimated/issues/2028
Version of Realm and Tooling
- Realm JS SDK Version: 10.4.1
- Node or React Native: 0.63.4
- Client OS & Version: Android
- Which debugger for React Native: N/A
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 13
- Comments: 36 (8 by maintainers)
Commits related to this issue
- bump: Realm to "hermes" build Trying to debug issue where debugger crashes on restart: https://github.com/software-mansion/react-native-reanimated/issues/1424 https://github.com/realm/realm-js/issues... — committed to trkwll/react-native-queue by trackwell-mike 2 years ago
- Upgraded realm to fix https://github.com/realm/realm-js/issues/3837 — committed to bithyve/bitcoin-keeper by PraneethGunas 2 years ago
Same problem, we have to use reanimated v2 to for other dependencies, and it’s urgent for us to find a solution to use both together. Looking forward to hear more
Hi @kneth, any news on this one yet?
We’re starting on the implementation of something which would be a lot simpler in reanimated v2 due to the new API but we’re having to stick to v1 for now due to this conflict with Realm.
FYI, I’ve retested with the latest versions of both projects (Realm 10.6.1 and Reanimated 2.2.0) but, unsurprisingly, it still happens. Interestingly the behaviour seems somewhat variable? Possibly a race between the two modules hooking into the JSC?
If I use the minimal repro off of the reanimated ticket (https://github.com/limpbrains/reanimated-2-playground) it doesn’t always crash when I hit the ‘write to realm’ button. Sometimes it crashes the app (seems more likely if I tap the button as soon as it’s available, rather than waiting) but when it does ‘work’ I’ve seen varying output from the console.log statement:
Also, if there’s anything extra we can provide to help (tombstones, etc) let us know.
Our Hermes release branch currently solves all issues related to Reanimated v2. Please use this branch if your project needs
react-native-reanimated. If you are having any issues with the current Hermes release branch, please open a new ticket describing your issue.To quickly switch to this release branch, use the following command:
We are actively working on this branch, so any input would be appreciated 😃
I don’t think there’s any other workarounds that I am aware of, although perhaps someone from the community has some ideas. We’re hoping we can solve the performance regressions soon. Sorry, I realise it’s not ideal, but since realising the impact we are treating this as a high priority.
@liamjones Yes, you do not need to enable Hermes for this to work.
A part of the hermes effort was fixing the bridge between Android and the javascript engine. This fixes the conflict we were having with the way
react-native-reanimatedestablishes this bridge.No worries, I know you’re working hard on this. I want the JSI implementation to work because when it does it will be 🔥
Sounds like you’re close!
thanks @liamjones
@AzadMohammadi-z Please take a look at https://github.com/realm/realm-js/blob/v11/COMPATIBILITY.md to find a compatible version. Best is to upgrade to latest version but it will also include upgrading React Native.
I’m using realm@hermes as @takameyer suggested and it is working, there are still some random crashes but it is better than without it.
@hungnv2010 then please attach some reproducible example, because the original issue was about data loss or crash on reload. Looks like you have something different here
Anyone who is eager to have this issue fixed, please try the latest betas of 10.20 with hermes support. In my experiments, it was working out of the box
Same having this problem with realm + reanimated v2 which is a major problem as reanimated v2 looks like a requirement for some camera packages i need
https://github.com/software-mansion/react-native-reanimated/issues/1424
Oh! Yes, v1 works here too. It’s only an issue with v2 (which we’re trying to upgrade to for the new API).
Thank you for cross-posting. We will have to investigate it further to understand the interaction between JavaScriptCore and the two libraries is.