realm-js: addListener notification is empty (documentation only)
When using addListener(objects, changes) on React Native iOS it always returns empty on the first notification and the second notification returns what should have been in the first one.
I found in results-tests.js below that first notification is empty.
Is this by design or am I doing something wrong here? 😀
realm.objects('TestObject').addListener((testObjects, changes) => {
// TODO: First notification is empty, so perform these
// assertions on the second call. However, there is a race condition
// in React Native, so find a way to do this in a robust way.
//TestCase.assertEqual(testObjects.length, 4);
//TestCase.assertEqual(changes.insertions.length, 1);
resolve();
});
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 10
- Comments: 27 (5 by maintainers)
@sheshavpd This was a critical issue for me as well, and for now I got it working by doing
realm.write(() => {})
(basically a second empty write) after each write. Far from ideal and may not be feasible in your context, but it’s been working well for me in the meantime.Realm: 1.12.0 RN: 0.47 Platform: iOS 11 BUT only in simulator - on iPhone SE no problem
➤ Stoney Burks commented:
We discussed in team meeting that this issue specifically will be handled through documentation. We will, however, create a new feature/enhancement ticket to address long-term solutions.
Also having this issue in React Native with Realm 1.3.1. After banging my head for a few hours trying to figure out what I was doing wrong I finally realized that these notifications are just always one
realm.write()
behind. I eventually just added and additionalrealm.write(() => {})
call which makes it trigger the notification I need right away. Definitely seems to work as a workaround, but looking forward to having a real fix for this.