realm-js: only Android: Cannot access realm that has been closed(realm react)

How frequently does the bug occur?

All the time

Description

RealmContext.js

import { ContactInfo, Room, RoomBackground, RoomDetail, RoomMessage, Summary } from "../database/RealmSchemas"
import { Realm, createRealmContext } from '@realm/react'

const config = {
    schema: [Room.schema, 
        ContactInfo.schema, 
        RoomDetail.schema, 
        RoomBackground.schema, 
        Summary.schema, 
        RoomMessage.schema],
}

export default createRealmContext(config)

Other class

import RealmContext from '../../context/RealmContext'
const { useRealm, useQuery } = RealmContext
export class....{
    const realm = useRealm()
    ... get data....

Stacktrace & log output

ReactNativeJS: { [Error: Cannot access realm that has been closed.

Can you reproduce the bug?

Yes, always

Reproduction Steps

as Description Define realm context get Realm instance => const { useRealm } = realmContext create realm => const realm = useRealm() query data

Version

“realm”: “^10.18.0”, “@realm/react”: “^0.3.0”,

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

Android simulator sdk 30

Build environment

Which debugger for React Native: … npm -v not ok Use npm v8.18.0 node -v not ok Use node v17.9.1 (current: v17.8.0)

Cocoapods version

android problem

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 32 (9 by maintainers)

Most upvoted comments

"react-native-reanimated": "^2.9.0",

This is not compatible with Realm v10 on Android. We have a release candidate for v11.

Can you try:

npm install realm@11.0.0-rc.0
"react-native-reanimated": "^2.9.0",

This is not compatible with Realm v10 on Android. We have a release candidate for v11.

Can you try:

npm install realm@11.0.0-rc.0

Thanks solved the issue, I had realm 10.20.0-beta.5 and react-native-reanimated 2.5.0

Ahh, i found the problem, the scheme class does not contain import Realm, but I dont know why IOS does not make crash, only Android. Im really thanks you for your help Here is my RealmSchema: Screen Shot 2022-08-24 at 14 34 21

@fukemy That code looks fine. I’m going to follow up with some questions.

Can you try and implement the fallback property on the RealmProvider? This makes sure the children are not rendered until the realm context is set. The following example should suffice:

return (
    <RealmProvider fallback={() => null}>
...
</RealmProvider>

Are you using realm in any other way outside of the useRealm hook? If you, for example, open and close a realm within a useEffect then this would also close the realm returned from the useRealm hook.

thanks, i will try to make a small project to reproduce