[cloud_firestore]: iOS includeMetadataChanges on document snapshots does not receive fromCache events correctly #12761
Labels
platform: ios
Issues / PRs which are specifically for iOS.
plugin: cloud_firestore
resolution: fixed
A fix has been merged or is pending merge from a PR.
type: bug
Something isn't working
Is there an existing issue for this?
Which plugins are affected?
Core, Cloud_Firestore
Which platforms are affected?
iOS
Description
On an iOS device, using
includeMetadataChanges
does not work correctly for single document snapshots (which works correctly for collection snapshots which was fixed in this week's commit #12739) for both:The following examples were tested on an iOS Simulator, but the same problem exists on real devices as well.
These examples compare the behavior of Collection snapshots (which work as expected) and Document snapshots (that behave unexpectedly).
Example: Collection Snapshot (works as expected)
Launching the app
When we launch the app, first we receive data from the cache and then we receive data from the database (as expected):
Regaining connection to DB
Process: After disconnecting the simulator from an internet connection, I will send a modification to the database. Then I will enable the internet connection.
Received events (as expected):
Example: Document Snapshot (incorrect behavior)
Launching the app (for the second time - the first time we don't have any data cached so we will receive the event
fromCache: false
)When we launch the app, we receive data from the cache, but we do not receive the event from the server (which would be expected).
The
FromCache: false
event is not received when the query is first executed, but it will be received only after data is updated in the database (or we send a modification from the app).Regaining connection to DB
Process: After disconnecting the simulator from an internet connection, I will send a modification to the database. Then I will enable the internet connection.
Received events:
As opposed to Collection Reference, we did not receive the event
fromCache: true
after we lost the database connection. We also do not receivefromCache: false
events after the connection is regained nor after all modifications are written.We will receive the
fromCache: false
event only after the data in the database is updated which is not expected behavior.Expected behavior:
Both single document snapshots and collection snapshots should behave consistently.
The correct behavior is of the collection snapshots.
Appendix:
This issue has already been reported once for collection snapshots: #12722.
The conclusion was a new ticket to ios sdk (firebase/firebase-ios-sdk#12869), where the solution was to change
addSnapshotListenerWithOptions:options
toaddSnapshotListenerWithOptions:optionsWithSourceAndMetadata
.Thus a bug fix was pushed to flutterfire.
However going into the fix (#12739), I noticed that only file
FLTQuerySnapshotStreamHandler.m
was updated with this change, but fileFLTDocumentSnapshotStreamHandler.m
does not have these changes applied.Reproducing the issue
Create a new Flutter app and connect it to Firebase. In this app, create a new listener that will observe document snapshots with metadata changes.
Test both of these scenarios:
An app I used for testing is available at:
https://github.com/TypeSoft-Ltd/firebase-metadata-changes-bug
To test different behavior between collection and document snapshots, change the
useDocumentReference
bool property totrue
andfalse
on widgetTestMetadataChangesPage
in theapp/widget/app_root.dart
Firebase Core version
2.31.0
Flutter Version
3.19.5
Relevant Log Output
No response
Flutter dependencies
Expand
Flutter dependencies
snippetExpand
flutter doctor -v
snippetAdditional context and comments
No response
The text was updated successfully, but these errors were encountered: