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

ObjectID Inconsistency on read #3622

Closed
maxencehenneron opened this issue Mar 3, 2021 · 14 comments
Closed

ObjectID Inconsistency on read #3622

maxencehenneron opened this issue Mar 3, 2021 · 14 comments

Comments

@maxencehenneron
Copy link

maxencehenneron commented Mar 3, 2021

Goals

When reading objects, the ObjectId type is not an instance of ObjectId.

Expected Results

When reading an object with object ids, the property should be an instance of ObjectID

Actual Results

The property is in the following format:
["$oid", "603f6df28095c5cd1410d0f8"]

(an array of strings)

Steps to Reproduce

Given the following schema:

    static schema: Realm.ObjectSchema = {
        name: 'User',
        primaryKey: '_id',
        properties: {
            _id: 'objectId',
            name: 'string',
        }
    };

Creating an user like this:

          realm?.write(() => {
            realm.create(
              User.schema.name, 
              {
                _id: new ObjectId(),
                name: "Test user",
              }
            );
          });

When reading the users like this:

realm.objects<User>(User.schema.name)

The "_id" property isn't a ObjectId, but an array of strings.

Code Sample

See above

Version of Realm and Tooling

  • Realm JS SDK Version: 10.2.0
  • Node or React Native: React Native
  • Client OS & Version: React native 0.63.4
  • Which debugger for React Native: Chrome
@maxencehenneron
Copy link
Author

Please note: This only happens when debugging on chrome. Without a debugger, everything is working as expected.

@kraenhansen
Copy link
Member

Thanks for the detailed bug-report, we'll have to investigate further.

@bimusiek
Copy link
Contributor

Is there any planned date for the fix to be made? It blocks debugging React Native apps if you use ObjectIds from Realm.
For example, we use in our code .toHexString() which fails when the objectid is a 2 element array.

We have a workaround, however it seems quite important for developing RN apps with Realm.

@kneth
Copy link
Contributor

kneth commented Mar 18, 2021

If you are debugging on iOS, you can use Safari Dev Tools to connect to your device's JS engine.

@xbaun
Copy link

xbaun commented Aug 1, 2021

Is there any progress on this issue? I just stumbled upon this myself and I am wondering how to debug my RN app when accessing an ObjectId. As a workaround I have written a small Type Guard utility function that extracts the value, but that is not a permanent solution that I like.

@takameyer
Copy link
Contributor

@xbaun We have looked into it, but unfortunately it is not a trivial fix. Our current efforts are focused on getting Flipper to work with realm.
In the meantime, please use Safari to debug if possible.

@xbaun
Copy link

xbaun commented Aug 2, 2021

@takameyer Ok thanks. I tried to debug RN with Safari (as described in the linked article), but the source tab of Safari does not load source maps... But this is another problem I think.

@takameyer
Copy link
Contributor

@xbaun Me and others also had this problem. This seems to be a problem with the current version of Safari. It should work with the Safari Technology Preview.

@xbaun
Copy link

xbaun commented Aug 2, 2021

@takameyer thanks for the hint 👍 I will try the tech preview.

@takameyer
Copy link
Contributor

We have decided to close this as we do not plan to provide further support for the chrome debugger.

@takameyer takameyer removed their assignment Aug 2, 2021
@xbaun
Copy link

xbaun commented Aug 2, 2021

@takameyer Debugging with Safari works for me now, but the result is the same as with Chrome (see image below). Under Safari, should the ObjectId be correctly deserialized into an object and not an array? Dropping the support for Chrome seems not to be the solution ... or am I missing something?

image

@takameyer
Copy link
Contributor

takameyer commented Aug 3, 2021

@xbaun It seems you still have the "debugger" enabled. In Safari you can debug without actually activating Debug with Chrome. Then the JavaScript bundle will be directly interpreted by the JS Engine in the simulator and not the JS Engine in Chrome browser (which essentially is why we have problems with Chrome support).

However, I have just attempted this as well in a sample app and it appears Safari also has trouble accessing Realm data.

image

I have made a separate issue for this, which we will continue to investigate #3880

@takameyer
Copy link
Contributor

takameyer commented Aug 3, 2021

I'd also like to add an amendment to the closing of this issue. Realm works by extending the core functionality of the JSC engine. Unfortunately, this makes the Chrome debugger nearly impossible to use, since it is interpreting the JavaScript through the Chrome browser JavaScript engine, which does not contain Realm. A workaround was implemented, which has been nearly acceptable, but has been a burden to maintain. Therefore we are going to put effort into supporting alternative debugging experiences. You can follow our progress on supporting Flipper (which requires us to support Hermes) in this PR #3792

In the meantime, we recommend using Safari debugging. To view the contents of your Realm object using the toJSON function. The following screenshot shows an example of the output, which correctly interprets ObjectId.

image

@xbaun
Copy link

xbaun commented Aug 3, 2021

After a macOS update and reboot, the Technical Preview and default Safari now show sources directly in the JSContext window without Debug with Chrome enabled. Thanks for all the help so far.

I now have the same error as you described above but the application does'nt break anymore when accessing the ObjectId.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants