Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-2271

RealmProvider does not load children when offline

      How frequently does the bug occur?

      Always

      Description

      The issue comes when the app is freshly started and a user is logged in (NOT as an anon-user) and the device is offline. In that case the RealmProvider that uses the sync configuration is stuck in the LoadingScreen and does not show the children.

      I would have expected that the local Realm instance would be used.

      This is how my component tree looks like:

          <AppProvider id={REALM_APP_ID}>
            <UserProvider fallback={UserProviderFallbackComponent}>
              <RealmProviderComponent>
                {children}
              </RealmProviderComponent>
            </UserProvider>
          </AppProvider>
      

      and RealmProviderComponent looks like this:

       
      import { useApp, useUser } from "@realm/react";
      import * as React from "react";
      import { ClientResetMode } from "realm";
      import LoadingScreen from "../screens/LoadingScreen";
      import { RealmProvider } from "./RealmProviderContext";
      import { config } from "./schema";
      
      interface RealmProviderComponentProps {
        children?: React.ReactNode;
      }
      
      const RealmProviderComponent = ({ children }: RealmProviderComponentProps) => {
        const app = useApp();
        const user = useUser();
      
        const realmRef = React.useRef<Realm | null>(null);
      
        React.useEffect(() => {
          user.refreshCustomData().catch((error) => console.log(error));
        }, [user]);
      
        if (user.providerType === "anon-user") {
          return (
            <RealmProvider fallback={<LoadingScreen message="Anon user" />}>{children}</RealmProvider>
          );
        }
      
        return (
          <RealmProvider
            realmRef={realmRef}
            fallback={<LoadingScreen message={`User ${user.id}`} />}
            sync={{
               user,
               flexible: true,
               initialSubscriptions: {...},
               clientReset: {...}
               onError: () => {}
            }}
          >
            {children}
          </RealmProvider>
        );
      };
      
      export default RealmProviderComponent;
      
      

      Stacktrace & log output

      No response

      Can you reproduce the bug?

      Always

      Reproduction Steps

      1. Use RealmProvider with Atlas Device Sync configuration
      2. Open app and login with user account
      3. Close app
      4. Put device in airplane mode to simulate offline mode
      5. Open app again

      Version

      @realm/react: 0.4.1

      What services are you using?

      Atlas Device Sync

      Are you using encryption?

      No

      Platform OS and version(s)

      iOS 16.3.1 (latest)

      Build environment

      Which debugger for React Native: ..

      Cocoapods version

      No response

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: