realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.8k stars 577 forks source link

UserProvider.js throwing app.addListener is not a function error #4638

Closed lukewalz closed 2 years ago

lukewalz commented 2 years ago

How frequently does the bug occur?

All the time

Description

I am seeing an error when setting up realm/react with the user provider . My app is stuck on the splash screen and I get an error in my console that looks like this. This error comes straight from the UserProvider.js file in the react/realm package. Is this intended?

Stacktrace & log output

ExceptionsManager.js:149 TypeError: app.addListener is not a function

This error is located at:
    in UserProvider (at App.tsx:67)
    in AppProvider (at App.tsx:66)
    in App (at sdk.js:98)
    in ReactNativeProfiler (at sdk.js:97)
    in RCTView (at View.js:32)
    in View (at touchevents.js:23)
    in __Sentry.TouchEventBoundary (at sdk.js:96)
    in RootApp (at renderApplication.js:50)
    in RCTView (at View.js:32)
    in View (at AppContainer.js:92)
    in RCTView (at View.js:32)
    in View (at AppContainer.js:119)
    in AppContainer (at renderApplication.js:43)
    in thedriverclient(RootComponent) (at renderApplication.js:60)

Can you reproduce the bug?

Yes, always

Reproduction Steps

No response

Version

@realm/react": "^0.3.1"

What SDK flavour are you using?

Atlas Device Sync

Are you using encryption?

No, not using encryption

Platform OS and version(s)

ios

Build environment

React Native Debugger

Cocoapods version

1.11.3

takameyer commented 2 years ago

@lukewalz Thanks for reporting. We have just released adding listeners to app and user on master, but the Hermes branch of Realm doesn't have these changes yet. This should work with latest realm release. Which version of realm are you using?

lukewalz commented 2 years ago

@lukewalz Thanks for reporting. We have just released adding listeners to app and user on master, but the Hermes branch of Realm doesn't have these changes yet. This should work with latest realm release. Which version of realm are you using?

10.9.1

takameyer commented 2 years ago

@lukewalz @realm/react 0.3.1 requires realm 10.17.0 or higher. That should remove the issue. You will have to update your pods with pod install and rebuild in order for the changes to take effect.

lukewalz commented 2 years ago

@lukewalz @realm/react 0.3.1 requires realm 10.17.0 or higher. That should remove the issue. You will have to update your pods with pod install and rebuild in order for the changes to take effect.

I mistyped. ^10.19.1 is my current realm version

tomduncalf commented 2 years ago

Hi @lukewalz, are you able to share a reproduction for your issue please? I created a new app with our Realm React template (npx react-native init ProjectName --template @realm/react-native-template-ts) and ensured I had realm@10.19.1 and @realm/react@0.3.1 installed, enabled sync, and I have no issues running it.

lukewalz commented 2 years ago

For what its worth, the template had the same issue for me when I selected the sync version. I didn't set up the schemas or anything for that in the realm dashboard though so that could explain it.

I also am using partition instead of flexible if that matters

Sure. Here is some code. Let me know if you need anything else

schemas

import Realm from 'realm';

export const rideSchema = {
  name: 'ride',
  properties: {
    _id: 'objectId?',
    date_completed: 'date?',
    date_created: 'date?',
    date_requested: 'date?',
    duration: 'double?',
    locations: 'string[]',
    notes: 'string?',
    passengers: 'int?',
    service: 'string?',
    status: 'int?',
    tip: 'double?',
  },
  primaryKey: '_id',
};

export const userSchema = {
  name: 'user',
  properties: {
    _id: 'objectId',
    account_type: 'int?',
    address: 'string?',
    auth_id: 'string',
    city: 'string?',
    creation_date: 'date?',
    email: 'string?',
    first_name: 'string?',
    hours: 'int?',
    last_name: 'string?',
    notification_keys: 'string[]',
    phone: 'string?',
    plan: 'int?',
    profile_image: 'string?',
    rides: 'ride[]',
    state: 'string?',
    zip: 'string?',
  },
  primaryKey: '_id',
};

App.tsx =>

const config = {
  schema: [userSchema, rideSchema],
};

export const {RealmProvider, useObject, useQuery, useRealm} =
  createRealmContext(config);

const syncConfig = {
  partitionValue: null as any,
};

    <AppProvider id=[redacted]>
      <UserProvider fallback={Login}>
        <RealmProvider sync={syncConfig} fallback={() => <ActivityIndicator />}>
        </RealmProvider>
      </UserProvider>
    </AppProvider>

package.json

  "dependencies": {
    "@react-native-firebase/app": "^14.9.1",
    "@react-native-firebase/messaging": "^14.9.1",
    "@react-native-firebase/storage": "^14.9.4",
    "@react-native-picker/picker": "github:react-native-picker/picker",
    "@react-navigation/native": "^6.0.10",
    "@react-navigation/stack": "^6.2.1",
    "@realm/react": "^0.3.1",
    "@sentry/react-native": "^3.4.2",
    "@types/realm": "^1.13.0",
    "formik": "^2.2.9",
    "moment": "^2.29.3",
    "react": "17.0.2",
    "react-native": "0.68.0",
    "react-native-bootsplash": "^4.1.4",
    "react-native-date-picker": "^4.2.1",
    "react-native-gesture-handler": "^2.4.0",
    "react-native-google-places-autocomplete": "^2.4.1",
    "react-native-image-picker": "^4.8.3",
    "react-native-paper": "^4.12.0",
    "react-native-safe-area-context": "^4.2.4",
    "react-native-screens": "^3.13.1",
    "react-native-sms": "^1.11.0",
    "react-native-vector-icons": "^9.1.0",
    "realm": "^10.19.1",
    "use-sync-external-store": "^1.1.0",
    "yup": "^0.32.11"
  },
tomduncalf commented 2 years ago

Hey @lukewalz,

I took your schema and created a simple test app based on the React Native Typescript template. This seems to have no issues syncing.

Could you try it out please and see if it works for you? https://github.com/tomduncalf/Issue4638AddListenerUndefined (npm install, npx pod-install, npm run ios) – you can use my app ID for now, I'll delete the app once this is resolved.

If it works for you then we'll need to work out where your app is differing – you can see the changes I made to the RN template here: https://github.com/tomduncalf/Issue4638AddListenerUndefined/commit/c31aa0ce03ff8ec8382c989d8570191bbf1a50cc

lukewalz commented 2 years ago

hey @tomduncalf, I very much appreciate the quick responses and help. If I clone that branch that you posted, The app works without issue. However, when I clone the template and make the changes you outlined in https://github.com/tomduncalf/Issue4638AddListenerUndefined/commit/c31aa0ce03ff8ec8382c989d8570191bbf1a50cc , I get the same app.addListener error. I can't find differences but something must be going wrong with my template. I have created a repo for your reference. I will keep digging to see differences.

tomduncalf commented 2 years ago

Hey @lukewalz... so you see the issue with your repo that you linked there? I just cloned it and I don't see any issues. Is there anything specific I need to do to repro this? Are you running on the iOS simulator?

lukewalz commented 2 years ago

Yes I am running on the iphone 13 simulator. IS that an issue? Other than that, I just did the standard npx run ios

On Mon, Jun 20, 2022, 6:01 AM Tom Duncalf @.***> wrote:

Hey @lukewalz https://github.com/lukewalz... so you see the issue with your repo that you linked there? I just cloned it and I don't see any issues. Is there anything specific I need to do to repro this? Are you running on the iOS simulator?

— Reply to this email directly, view it on GitHub https://github.com/realm/realm-js/issues/4638#issuecomment-1160303868, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF7SETB2MTS7UGNTWHK4O2LVQBFP5ANCNFSM5YKVMKUA . You are receiving this because you were mentioned.Message ID: @.***>

lukewalz commented 2 years ago

My mistake, that one is working now. I will just have to keep examining the differences between the template code and my own. Thanks for all the help. If I find something obvious, I will post a solution.

tomduncalf commented 2 years ago

OK @lukewalz, please feel free to reopen the issue if you need more assistance!

lukewalz commented 2 years ago

After weeks of trying different react-native, realm, and react-realm versions, this issue still persists. Even the template project (adjusted for my case) throws the same error. Do I possibly have the wrong tier of atlas? I am out of ideas. I have a repo that I hope will help you reproduce the error.

https://github.com/lukewalz/AwesomeProject

React Native Debugger

Screen Shot 2022-07-07 at 1 56 42 AM

Simulator

Screen Shot 2022-07-07 at 1 58 41 AM

.

takameyer commented 2 years ago

@lukewalz app.addListener was added to Realm in version 10.17.0. It seems to be that you somehow have an outdated version of realm. Can you confirm the realm version in node_modules/realm/package.json is greater that 10.17.0? And also to rule out the obvious:

cd ios
rm -rf Pods
rm Podfile.lock
rm -rf ~/Library/Developer/Xcode/DerivedData
pod install
takameyer commented 2 years ago

@lukewalz I ran your project just fine. Here are the commands (with comments) that i typed:

git clone https://github.com/lukewalz/AwesomeProject.git
cd AwesomeProject
ruby -v # made sure my ruby version matched what was in the Gemfile
vi Gemfile #updated the gemfile to my current version (2.7.5)
bundle install #this installs cocoapods
yarn 
npx pod-install
npx react-native run-ios
dsdlt commented 2 years ago

I'm experiencing the same issue. The application runs but this error appears if you enable Chrome debugger in the app.

image
takameyer commented 2 years ago

@david011111000101 we are not compatible with the Chrome debugger, so I would expect this error to pop up when it's turned on. Please refer to our README for debugging alternatives.

lukewalz commented 2 years ago

Chrome debugger was the issue. I had to get everything changed over to Flipper