Closed nzapponi closed 2 months ago
➤ PM Bot commented:
Jira ticket: RJS-2887
Try to set closeOnUnmount
to false (https://www.mongodb.com/docs/atlas/device-sdks/sdk/react-native/api-reference/realm-provider/)
Ok so I tried to set closeOnMount
to false and, whilst the app no longer crashes, it's still acting very weird.
Basically, it seems like RealmProvider
re-renders all of its children after any action.
The app loads correctly, but the moment I press on anything, every child of RealmProvider
gets re-rendered and, in my case, expo-router resets the whole app to the entry point.
There's nothing appearing in the logs when that occurs.
Having the same issue, upgrading from 0.7.0 to anything higher makes my app rerender continuously.
I am having the same issue. 0.7.0 works well, but all other versions are broken.
Reproduction:
export default function Layout() {
return (
<RealmProvider schema={schema} closeOnUnmount={false}>
<TextInput />
</RealmProvider>
);
}
Focusing the text input will always re-render the children of RealmProvider on Android, so the keyboard always hides.
I tried to setup a project to debug, but I've failed to reproduce it consistently. Would any of you be able to share a link to a repository which has this symptom? As minimal as possible to trigger the issue and instructions on the steps I'd have to take 🙏
Never mind - I got a reliable reproduction and fixed the issue. Look out for an upcoming release 👍 Thanks a lot for reporting this @nzapponi and for your patience 💙 @RemiHin & @skoob13!
Awesome thanks for the support!!
The fix is released as @realm/react@0.10.1
- please take it for a spin and report back 🤞
Yeah, issue resolved. Thanks!
So what are the best practices now for using @realm/react with expo-router
and other react navigation libraries that have, to my understanding, separate DOM trees per screen? Do we need to wrap each screen in a Realm Provider? Or can we have just one top level RealmProvider in our _layout file? Or does that need closeOnUnmount
set to false?
FWIW I kept my original code structure, with a single provider in my app layout, and it just works.
With the update I didn't have to set closeOnMount: false
, since in any case my provider never unmounts.
Not sure if that's the recommended best practice though!
How frequently does the bug occur?
Always
Description
Unable to keep the app running, the realm keeps getting closed for no reason
Stacktrace & log output
Can you reproduce the bug?
Always
Reproduction Steps
This is how the provider is initialized:
This provider only mounts once, so it shouldn't ever close.
Version
0.8.0+
What services are you using?
Local Database only
Are you using encryption?
Yes
Platform OS and version(s)
iPhone 15, OS 17.5
Build environment
Expo 51.0.26 Realm 12.12.1
Cocoapods version
No response