firebase-ios-sdk
firebase-ios-sdk copied to clipboard
Realtime Database: Database listener clears children when performing another query in same ref
Description
For a chat application I am doing a double query, I have a listener for new messages, and a paginated query for old messages.
I just discovered that my listener is impacted by the queries I do on that same path, which I believe shouldn't be the case
Reproducing the issue
final database = FirebaseDatabase.instance;
final path = '/test_path';
String? randomKey;
for (var i = 0; i < 10; i++) {
final ref = database.ref(path).push();
if (i == 5) {
randomKey = ref.key;
}
await ref.set('test $i');
}
final ref = database.ref(path);
var hasQueried = false;
ref.orderByKey().startAt(randomKey).onValue.listen((event) {
print('listener ${event.snapshot.children.length}');
if (!hasQueried) {
hasQueried = true;
ref.orderByKey().limitToLast(3).endBefore(randomKey).get().then((data) {
print('obtained previous messages ${data.children.length}');
});
}
});
Firebase SDK Version
11.2
Xcode Version
16.1
Installation Method
CocoaPods
Firebase Product(s)
Database
Targeted Platforms
iOS
Relevant Log Output
listener 5
obtained previous messages 3
listener 0
If using Swift Package Manager, the project's Package.resolved
Expand Package.resolved snippet
Replace this line with the contents of your Package.resolved.
If using CocoaPods, the project's Podfile.lock
Expand Podfile.lock snippet
Replace this line with the contents of your Podfile.lock!
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
The issue was first reported here https://github.com/firebase/flutterfire/issues/13822, will submit the Podfile.lock shortly!
May be related to long-standing #12168
Closing in favor of https://github.com/firebase/firebase-ios-sdk/issues/12168.