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

realmRef on RealmProvider doesn't allow syncSession.addProgressNotification #5144

Open
LukeStorry opened this issue Nov 25, 2022 · 4 comments

Comments

@LukeStorry
Copy link

LukeStorry commented Nov 25, 2022

How frequently does the bug occur?

All the time

Description

We're having issues getting anything out of realmRef.current

  • it appears to always be either null, an empty object, or {"syncSession": undefined} when logging the results.

Previously using const realm = useRealm(); realm.syncSession.addProgressNotification(...) within the Realm Provider worked well.

Now we'd like to use the values from this progress notification to display within the fallback component to display a loading update to users for longer syncs.

However, when trying to use the realmRef as described in #4571, the value provided is either empty, or doesn't trigger a useEffect when needed.

Stacktrace & log output

No response

Can you reproduce the bug?

Yes, always

Reproduction Steps

Here is a reduced reproduction:

export function RealmAppProvider({children}: {children: React.ReactNode}) {
  const [syncProgress, setSyncProgress] = React.useState(0);
  const realmRef = React.useRef<Realm | null>(null);
  const appRef = React.useRef<Realm.App | null>(null);

  React.useEffect(() => {
    const realm = realmRef.current;
    console.log({realm});
    if (realm) {
      console.log('we have realm!');
      const syncSession = realm.syncSession;
      if (syncSession) {
        console.log('we have syncSession!');
        syncSession.addProgressNotification(
          Realm.ProgressDirection.Download,
          Realm.ProgressMode.ReportIndefinitely,
          (transferred, transferable) => {
            console.log({transferred, transferable});
            if (transferable > 0) {
              setSyncProgress(transferred / transferable);
            }
          },
        );
      }
    }
  }, [realmRef.current?.syncSession?.state, setSyncProgress]);

  React.useEffect(() => {
    console.log('SyncProgress: ', syncProgress);
  }, [syncProgress]);

  return (
    <AppProvider id={REALM_APP_ID} appRef={appRef}>
      <LdtAuthProvider>
        <UserProvider fallback={<AuthNavigator />}>
          <RealmProvider
            realmRef={realmRef}
            sync={{
              flexible: true,
              initialSubscriptions: {
                update: (subs, realm) => {
                  const users = realm.objects('User');
                  subs.add(users, {name: 'User'});
                },
                rerunOnOpen: true,
              },
            }}
            fallback={<Text>{syncProgress} </Text>}>
            {children}
          </RealmProvider>
        </UserProvider>
      </LdtAuthProvider>
    </AppProvider>
  );
}

On app load, sync occurs, but the only console output is:

{"realm": null}
SyncProgress:  0 

Version

0.4.1

What SDK flavour are you using?

Atlas Device Sync

Are you using encryption?

Yes, using encryption

Platform OS and version(s)

MacOs 13.0

Build environment

No response

Cocoapods version

No response

@kneth
Copy link
Contributor

kneth commented Nov 28, 2022

Progress notification for flexible sync is not working as intended, and we are working (both server and client side) to provide a solution.

I will leave the issue open until we have released it.

@carbopilot
Copy link

Any update? :)

@gagik
Copy link
Contributor

gagik commented Jul 19, 2024

@carbopilot The upcoming realm update will fix the progress notification functionality for flexible sync, so we are also now looking into improving the experience of using progress notifications with @realm/react. See #5459 and #6797

@carbopilot
Copy link

Brilliant. Looking forward to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants