realm-js: Problems with Deleting Record with Realm for React Native

When I attempt to delete a record, my app instantly crashes and I cannot seem to catch the exception. From the MongoDB support team, it seems the context is being closed too soon. Any idea what is happening? This happens whether I use a listener or not.

image

Delete method:

  const deleteList = (listId: string): void => {
    const listRealm = realmRef.current;
    const list = listRealm?.objectForPrimaryKey<List>("List", new ObjectId(listId));
    try {
      listRealm?.write<void>(() => {
        if (list) {
          listRealm?.delete(list);
        }
      })
    } catch(error) {
      console.log(error);
    }
  };

React Native 0.70

SDK: android vRealmJS/10.21.1 Platform Version: 31

MongoDB version 5.0.12

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 34 (5 by maintainers)

Most upvoted comments

I think we have everything straightened out, for the most part. It seems that even if a listener is removed, it may not be completely removed. The code updates I made to handle this are as follows:

`  const listItemUpdateListener = (listItems: Realm.Collection<ListItem>) => {
    try {
      if (listItems.isValid()) {
        setListItems(getListItems(listItems));  
      }
    } catch(err) {
      console.error(err);
    }
  };
`

Yes, I will get what I can for you, as I can cause this exception to happen at will.

On Mon, Oct 10, 2022 at 9:32 AM Daniel Tabacaru @.***> wrote:

@s1tony https://github.com/s1tony do you have a stack trace and/or full client logs?

— Reply to this email directly, view it on GitHub https://github.com/realm/realm-js/issues/4948#issuecomment-1273408301, or unsubscribe https://github.com/notifications/unsubscribe-auth/AP57MNNESIXILFGWDQCQUTDWCQSF7ANCNFSM6AAAAAAQUZLDZY . You are receiving this because you were mentioned.Message ID: @.***>