After following instructions for Access a Synced Realm While Offline, it seems Realm is still trying to connect when my app launches and then hanging indefinitely on either a blank screen or a provided fallback view.
I have two schemas in my realm. One is configured for asymmetric sync (one way) and the other for flexible sync (two way).
When the app has a network connection, the sync service works as expected. It’s offline app launch that is crashing.
I’ve followed suggestions in similar questions linked below with no success:
mongoDB Forums
stack overflow
What I’ve tried:
- Wipe app data
- Launch app with network connection and login
- Close the app and re-open offline
Expectation: the app launches normally using the cached user and the local realm.
Result: The app hangs indefinitely on the fallback component provided in the sync configuration. Network errors appear in the console.
I’ve tried the code below with and without the initialSubscriptions
configuration.
I’ve also tried the Access After Timeout with Background Sync configuration.
Of note: the console.log
message in the sync onError
block never fires.
Any ideas or suggestions would be super appreaciated!
"expo": "~48.0.21",
"react": "18.2.0",
"realm": "^12.11.1",
"@realm/react": "^0.8.0",
const RealmWrapper = ({children}) => {
const [syncError, setSyncError] = useState(null);
const realmAccessBehavior = {
type: OpenRealmBehaviorType.OpenImmediately,
};
return (
<AppProvider id={APP_ID} logLevel={'trace'} logger={(level, message) => console.log(`[${level}]: ${message}`)}>
<UserProvider fallback={LoginWrapper}>
<RealmProvider
schema={[SurveyResults, SurveyDesign]}
fallback={<RealmLoading />}
sync={{
flexible: true,
existingRealmBehavior: realmAccessBehavior,
newRealmFileBehavior: realmAccessBehavior,
onError: (_, error) => {
console.log("I'm In the sync error handler!");
setSyncError(error);
},
initialSubscriptions: {
update(subs, realm) {
subs.add(realm.objects(SurveyDesign).filtered("name != nil"), {
name: "All Survey Designs",
behavior: WaitForSync.Never,
});
},
},
}}
>
{children}
</RealmProvider>
</UserProvider>
</AppProvider>
);
}```
ERROR [Realm.Sync.Client.Network – error] Failed to resolve ‘ws.services.cloud.mongodb.com:443’: Host not found (authoritative)
ERROR [Realm.App – error] App: request location failed (CustomError -1): request to https://…../location failed, reason: Network request failed
ERROR [Realm.App – error] App: refresh_access_token: …… -> 0 ERROR: request to https://……/location failed, reason: Network request failed