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

Realm object constructor must not return another value when debugger running #3673

Closed
aqos156 opened this issue Apr 2, 2021 · 4 comments
Closed

Comments

@aqos156
Copy link

aqos156 commented Apr 2, 2021

Goals

Debugging working with classes.

Actual Results

Snímek obrazovky 2021-04-02 v 15 18 32

Steps to Reproduce

Try to access a realm object instance when debugging.

This error seems to be still happening in 10.3.0 - we have just migrated our code to be compatible with the version 10.x.x from 3.x.x and are facing this issue. If we do not use a debugger (RN Debugger, Google Chrome debugger) it works as expected.

Model

export class User extends Realm.Object {
  static REGISTERED: number = 0;
  static GUEST: number = 1;
  static NOT_ACTIVATED: number = 2;

  static schema = {
    name: "User",
    primaryKey: "id",
    properties: {
      id: "int",
      etc...
    }
}

Accessing an object instance

const users = realm.objects("User");
console.log("Loaded", users[0]);

lib/browser/objects.js (the error is thrown here)

Snímek obrazovky 2021-04-02 v 15 12 47

Console output

Snímek obrazovky 2021-04-02 v 15 12 06

Error

Snímek obrazovky 2021-04-02 v 15 18 32

Version of Realm and Tooling

  • Realm JS SDK Version: 10.3.0
  • Node or React Native: 0.64.0
  • Client OS & Version: Big Sur 11.2.3
  • Which debugger for React Native: Tested with Chrom and React Native Debugger
  • Affecting Android (tested with 10) and iOS (14.4.2)
@aqos156
Copy link
Author

aqos156 commented Apr 2, 2021

I have read that this error has been happening in since version v5 and is described here #3007 and #2790 (I have posted this write-up also in the comments there)

Also I see that there have been many issues with same title, but all of them are closed and do not provide a working solution for us. If there is a solution somewhere or if you are working on something (I see some threads regarding Hermes) then please just point us to it.

@aqos156 aqos156 changed the title Realm object constructor must not return another value Realm object constructor must not return another value when debugger running Apr 6, 2021
@kneth
Copy link
Contributor

kneth commented Apr 7, 2021

#3642 discussed the use of class models. I mentioned the issue since User extends Realm.Object.

Our Chrome Debugger support is brittle. As an alternative, you can use Safari DevTool and attach it to you running app (actually, the JavaScriptCore instance on the simulator or device).

@aqos156
Copy link
Author

aqos156 commented Apr 7, 2021

@kneth Well in comparison to that issue we are not even using any constructors inside of our models and just to add the problem is being thrown even in safari dev tools (not tested with directly attaching to JavaScriptCore instance, I know this wasn't supposed to probably work).

If I remove these lines from the mentioned code:

if (constructor) {
    let result = constructor.call(object);
    if (result != null && result != object) {
        throw new Error('Realm object constructor must not return another value');
    }
}

Then it seems to work quite well while debugger is running, but I do not know much about this codebase, so I don't know if it breaks something later on.

Decorators

Another thing that has been bugging our team is the inability to utilize decorators inside of model properties in v10 (don't know compatibility in other version except in v3 it worked/works):

@model("User") // Defines model name and initializes schema - WORKS 
class User extends Realm.Object {
  // Defines type in schema - Doesn't work because the property becomes always undefined **without debugger**
  @property("string?") name?: string; 
}

Note: This is not related to the inner workings of the individual decorator, the problem is that even an empty decorator that doesn't do anything behaves the same. The decorators itself work, but the property is always undefined without debugger.

This works only in debugger ... These issue combinations seem to be getting comical to be honest 😆

I know there is an issue #877 already about this, but last activity is 2 years ago and it's only about official decorator support, which I don't need (and I suppose other people as well). The only thing that would be nice would be if the property decorators worked in production and development builds without dev tools. I have seen some investigation about workarounds for this problem in aklinker1/realm-ts-class-decorators#18 (comment), but it has not been resolved.

Is there anything that can be done about this situation?

@bmunkholm
Copy link
Contributor

Closing this as it will be resolved with the support for Hermes and the Flipper debugger. Please see here to try it out and provide feedback. Thanks for your patience!

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

3 participants