-
Notifications
You must be signed in to change notification settings - Fork 585
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
Realm is not defined
due to collection-methods.js
in Jest and while Remote Debugging
#4029
Comments
I can raise a cleaner version of the patch (https://gist.github.com/liamjones/cca9c81f26e0d998c9904d734e9be400) as a PR if you want but I couldn't get the builds/tests working when I checked out the realm-js repo locally so it might make sense for you to just make the code changes + test changes internally? |
Thanks for taking the time to write up this issue. To be completely honest, we are focussed on getting a version of Realm JS out which works well with Flipper. We already have an alpha release of this published. Once that is officially out, we will most likely discontinue our support of the (now legacy) Chrome Remote Debugger workflow and in that light, we probably won't be investigating this issue any further. Out of curiosity, would you be interested in moving from React Native Debugger to Flipper to resolve this issue? |
Unfortunately, that's not possible for us right now. Flipper's debugger is only for Hermes (AFAIK) and we're stuck on the JSC at the moment. We would ultimately like to try moving our apps over to Hermes and then we have to use Flipper's debugger I believe? Currently, we're blocked by Realm not supporting Hermes (I know you're working on it). Beyond that, I don't know how many other things will need changes when we try to migrate engines - we haven't been able to test yet because of the Realm blocker - and ours is a pretty chunky app so it may not be an easy thing to do if we find a lot of issues. I'm hopeful though! 🤞
How will JSC based projects debug their apps containing Realm in future then? Is there another option I'm not aware of? |
@liamjones We are currently recommending Safari for debugging. It requires a small addition to the |
Thanks, I'll take a look. It'll be a shame to lose the integrated Redux DevTools and React DevTools but it looks like both can be set up independently.
Sure. We have a manual mock for Realm in Jest that most of our tests use when they don't care about a real Realm. Code for the mock is here but I think it's probably irrelevant: https://gist.github.com/liamjones/2f7b50cef351f2aedb0adf796e83e11c However, we use linear migrations and have a test that uses real Realm to check these run correctly so we If I set various breakpoints in the manual mock, the test and Realm itself I can see the following happen:
I'm not sure if it is the manual mock causing issues - if I delete the mock entirely, remove the |
@takameyer I gave this a try today and the app exits/crashes as soon as I attempt to attach Safari to debug so this doesn't look like it's a solution for us on the JSC. 😞 |
This issue should be fixed by #4109 . |
How frequently does the bug occur?
All the time
Description
Upgraded from Realm 10.4.0 to 10.5.0+ (still present in 10.8.0)
Can no longer run Jest tests that use Realm or connect the Chrome Remote Debugger to the JSC, both error out with
Realm is not defined
.This was fixed in PR #3748 but that was closed without merging. Other bug reports for this issue include issue #3835 and issue #3991.
For now, we have patched Realm via patch-package with the code review suggestion on PR #3748 to work around this issue with the current implementation. Patch file: https://gist.github.com/liamjones/cca9c81f26e0d998c9904d734e9be400
Stacktrace & log output
Can you reproduce the bug?
Yes, always
Reproduction Steps
Unfortunately, I haven't been able to make a minimal repro that still triggers the issue yet and I don't really want to give you the entire source code to our app if I can help it.
For Jest, I thought it might be caused by the fact we normally have a manual mock for Realm in Jest (e.g.
__mocks__/realm.ts
) and thenjest.unmock('realm')
in one specific test to check our migration functions. However, just setting that up in a fresh RN project doesn't trigger the issue.Setting a breakpoint in the remote debugger on https://github.com/realm/realm-js/blob/v10.8.0/lib/collection-methods.js#L21 I can see that our RN app entry point
index.js
imports ourApp.tsx
and, as a result of dependencies, this eventually doesimport Realm from 'realm'
and whencollection-methods.js
is imported, Realm is already not defined (but it doesn't care at this point). Later on, a redux-saga is trying to load stuff from the DB, which results in https://github.com/realm/realm-js/blob/v10.8.0/lib/collection-methods.js#L60 executing and falling over due to Realm not being defined.Version
10.5.0, 10.8.0
What SDK flavour are you using?
Local Database only
Are you using encryption?
Yes, using encryption
Platform OS and version(s)
macOS 11.6
Build environment
Which debugger for React Native: React Native Debugger 0.12.1
RN 0.63.4
The text was updated successfully, but these errors were encountered: