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

Cannot compare realm.syncSession?.connectionState === Realm.ConnectionState[enumValue] #5480

Closed
mongodben opened this issue Feb 22, 2023 · 7 comments

Comments

@mongodben
Copy link
Contributor

mongodben commented Feb 22, 2023

How frequently does the bug occur?

Always

Description

when checking the value of Realm.syncSession.connectionState enum using an equality operator, such as:

// throws error :( 
realm.syncSession?.connectionState === Realm.ConnectionState.Connected

this code throws the following error:

    TypeError: Cannot read properties of undefined (reading 'Connected')

However, if I use the value of the enum (which i found by looking at the source code), things work as expected. For example:

// runs fine :)
realm.syncSession?.connectionState === 'connected'

I believe this might be related to some funky TS enum behavior, as talked about here https://stackoverflow.com/questions/50365598/typescript-runtime-error-cannot-read-property-of-undefined-enum (perhaps it's this issue?)


Additionally, in the API reference for this method, it describes the enum as accessible from Realm.App.Sync.ConnectionState, however in the SDK the enum is accessed through Realm.ConnectionState.

Also, the reference docs describe connectionState as a method, but in the SDK it is a property.

Also the docs for discussing realm.syncSession?.connectionState are pretty wrong (but I guess that's my problem to fix )

Stacktrace & log output

No response

Can you reproduce the bug?

Always

Reproduction Steps

No response

Version

realm@11.4.0 with @realm/react@0.4.1

What services are you using?

Atlas Device Sync

Are you using encryption?

No

Platform OS and version(s)

macOS 12.6.3

Build environment

Which debugger for React Native:

using React Native Testing Library, which i believe runs in a Node.js process.

Cocoapods version

No response

@kraenhansen
Copy link
Member

kraenhansen commented Feb 22, 2023

In the current latest version of the SDK, this enum is exported on Realm.App.Sync.ConnectionState as per https://github.com/realm/realm-js/blob/master/lib/extensions.js#L506-L510

Does this work?

realm.syncSession?.connectionState === Realm.App.Sync.ConnectionState.Connected

@kraenhansen
Copy link
Member

That being said. I agree we have an issue here, because we are indeed declaring this on the root level too.
I'll close this as a duplicate of #3365.

@kraenhansen kraenhansen closed this as not planned Won't fix, can't repro, duplicate, stale Feb 22, 2023
@mongodben
Copy link
Contributor Author

thank you for the speedy feedback @kraenhansen!

@mongodben
Copy link
Contributor Author

hi kraen, i've upgraded realm to 11.5.0, and the same issue persists. no change in behavior.

@kraenhansen
Copy link
Member

the same issue persists

Are you still using Realm.ConnectionState.Connected or did you update to use Realm.App.Sync.ConnectionState.Connected?

@krollins-mdb
Copy link
Contributor

@kraenhansen, I'm seeing the same behavior with the Realm.OpenRealmBehaviorType enums.

Using this behavior config object:

const realmAccessBehavior: Realm.OpenRealmBehaviorConfiguration = {
  type: Realm.OpenRealmBehaviorType.OpenImmediately,
};

Results in a TypeError:

TypeError: Cannot read properties of undefined (reading 'OpenImmediately')

But providing the value of the enum compiles just fine:

const realmAccessBehavior: Realm.OpenRealmBehaviorConfiguration = {
  type: 'openImmediately',
};

@kraenhansen
Copy link
Member

kraenhansen commented Feb 24, 2023

@krollins-mdb Thanks for highlighting this 👍 It seems we never provided an implementation for that, which is ... very unfortunate. I've made a quick PR for that: #5493

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
@sync-by-unito sync-by-unito bot closed this as completed Mar 15, 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

3 participants