App is crashing one time before the realm data loads

Hello @Andrew_Meyer i think i need you help again please. Since my last problem related here i have decided to remake my app from scratch without using reanimated 2.

But the app now is crashing once, on the first data loading. Then, if i reopen it the things go as it should be.

Im currently using the hooks exported by realm/react lib and i think im doing something wrong.

This is how im using ‘realm/react’ :slight_smile:

<AppProvider id={SYNC_CONFIG.appId}>
  <UserProvider fallback={SignIn}>
    <AppSync>
      <AppContextProvider> <-- this is my own context
        <PortalProvider>
          <App />
        </PortalProvider>
      </AppContextProvider>
    </AppSync>
  </UserProvider>
</AppProvider>

This is the code that crashes my app, just on the first time it is opened.


const formsResult = useQuery(Form);

// ... other code

useEffect(() => {
    function selectInitialForm() {
      if (currentUser) {
        const dbForms = formsResult.sorted('name');

        if (dbForms.length > 0) {
          setCurrentForm(dbForms[0]);   //<----- Logs inform this line is causing the crashes.
        }
      }
    }
    selectInitialForm();

  }, [currentUser, formsResult]);

This is the logs when it happens:

TypeError: object._objectId is not a function. (In 'object._objectId()', 'object._objectId' is undefined)

This error is located at:
    in UserStatisticsProvider (created by AppContextProvider)
    in AppContextProvider (created by RealmAppWrapper)
    in Unknown (created by AppSync)
    in AppSync (created by RealmAppWrapper)
    in UserProvider (created by RealmAppWrapper)
    in AppProvider (created by RealmAppWrapper)
    in ThemeProvider (created by RealmAppWrapper)
    in GestureHandlerRootView (created by GestureHandlerRootView)
    in GestureHandlerRootView (created by RealmAppWrapper)
    in RealmAppWrapper (created by ExpoRoot)
    in ExpoRoot
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:172:19 in handleException
at node_modules/react-native/Libraries/Core/ReactFiberErrorDialog.js:43:2 in showErrorDialog

TypeError: object._objectId is not a function. (In 'object._objectId()', 'object._objectId' is undefined)

This error is located at:
    in UserStatisticsProvider (created by AppContextProvider)
    in AppContextProvider (created by RealmAppWrapper)
    in Unknown (created by AppSync)
    in AppSync (created by RealmAppWrapper)
    in UserProvider (created by RealmAppWrapper)
    in AppProvider (created by RealmAppWrapper)
    in ThemeProvider (created by RealmAppWrapper)
    in GestureHandlerRootView (created by GestureHandlerRootView)
    in GestureHandlerRootView (created by RealmAppWrapper)
    in RealmAppWrapper (created by ExpoRoot)
    in ExpoRoot
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:172:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/expo-dev-launcher/build/DevLauncherErrorManager.js:44:19 in errorHandler
at node_modules/expo-dev-launcher/build/DevLauncherErrorManager.js:49:24 in <anonymous>
at node_modules/expo-error-recovery/build/ErrorRecovery.fx.js:12:21 in ErrorUtils.setGlobalHandler$argument_0

1 Like

I think this is related to [Needs help] Flexible sync not working on expo 45 · Issue #4625 · realm/realm-js · GitHub
There appears to be a conflict with how we link the android lib and Expo 45. Hopefully we will have a solution in the near future. Until then, the only work around i can provide is to use Expo 44.

@Andrew_Meyer I’m currently using Expo 44 and partition based sync. :neutral_face:
Should I try flexible? Is it production ready?

Are these errors occurring on React Native apps without expo?

@Diego_Jose_Goulart flexible sync is officially released this week, so we are directing all users to migrate there.
The issues you are currently having are only with Expo. We just need to do a new release of our -beta branch that is compatible with @realm/react and then that will also be compatible with the newest Expo.

@Andrew_Meyer I will make a git repository with a runnable example of my issue. Maybe you can give it a try, please?
In the meantime, I will test a version of my app without Expo and with flexible sync, hopefully it will be more stable.

Can we use flexible sync in production now?

Yes, it has been officially released for production.