-
Type: Bug
-
Resolution: Gone away
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: Realm React
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
- Use RealmProvider with Atlas Device Sync configuration
- Open app and login with user account
- Close app
- Put device in airplane mode to simulate offline mode
- 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