Skip to content

Commit 3748076

Browse files
committed
fix(firestore,windows): emit Pigeon objects on snapshot event sinks
The Pigeon 26 upgrade (#18205) changed the Dart-side EventChannel handlers in `method_channel_document_reference.dart` and `method_channel_query.dart` to expect the generated Pigeon class directly (`snapshot as InternalDocumentSnapshot` / `InternalQuerySnapshot`) and updated the Android stream handlers to emit `PigeonParser.toPigeonQuerySnapshot(...)` / `toPigeonDocumentSnapshot(...)` directly, but the Windows stream handlers in `cloud_firestore_plugin.cpp` were missed and still emitted `Parse...(...).ToEncodableList()`. As a result, on Windows every `DocumentReference.snapshots()`, `Query.snapshots()` and (transitively) `FirebaseFirestore.snapshotsInSync()` call threw `type 'List<Object?>' is not a subtype of type 'InternalDocumentSnapshot' in type cast` on the first event. Wrap the Pigeon class in `CustomEncodableValue(...)` so the Pigeon-aware codec on the EventChannel serializes it end-to-end, the same way Android does.
1 parent 456051e commit 3748076

1 file changed

Lines changed: 22 additions & 32 deletions

File tree

packages/cloud_firestore/cloud_firestore/windows/cloud_firestore_plugin.cpp

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,31 +1567,17 @@ class QuerySnapshotStreamHandler
15671567
firebase::firestore::Error error,
15681568
const std::string& errorMessage) mutable {
15691569
if (error == firebase::firestore::kErrorOk) {
1570-
flutter::EncodableList toListResult(3);
1571-
std::vector<flutter::EncodableValue> documents;
1572-
std::vector<flutter::EncodableValue> documentChanges;
1573-
1574-
for (const auto& documentSnapshot : snapshot.documents()) {
1575-
documents.push_back(ParseDocumentSnapshot(documentSnapshot,
1576-
serverTimestampBehavior)
1577-
.ToEncodableList());
1578-
}
1579-
1580-
// Assuming querySnapshot.getDocumentChanges() returns an iterable
1581-
// collection
1582-
for (const auto& documentChange :
1583-
snapshot.DocumentChanges(metadataChanges)) {
1584-
documentChanges.push_back(
1585-
ParseDocumentChange(documentChange, serverTimestampBehavior)
1586-
.ToEncodableList());
1587-
}
1588-
1589-
toListResult[0] = documents;
1590-
toListResult[1] = documentChanges;
1591-
toListResult[2] =
1592-
ParseSnapshotMetadata(snapshot.metadata()).ToEncodableList();
1593-
1594-
events_->Success(toListResult);
1570+
// Emit the Pigeon object directly so the Pigeon-aware codec on
1571+
// the EventChannel serializes it end-to-end. Pigeon 26 no longer
1572+
// flattens nested types, so sending a raw list here would cause
1573+
// the Dart side to receive a List<Object?> it can no longer
1574+
// decode into InternalQuerySnapshot.
1575+
events_->Success(CustomEncodableValue(InternalQuerySnapshot(
1576+
ParseDocumentSnapshots(snapshot.documents(),
1577+
serverTimestampBehavior),
1578+
ParseDocumentChanges(snapshot.DocumentChanges(metadataChanges),
1579+
serverTimestampBehavior),
1580+
ParseSnapshotMetadata(snapshot.metadata()))));
15951581
} else {
15961582
EncodableMap details;
15971583
details[EncodableValue("code")] =
@@ -1674,14 +1660,18 @@ class DocumentSnapshotStreamHandler
16741660

16751661
listener_ = reference_->AddSnapshotListener(
16761662
metadataChanges,
1677-
[this, serverTimestampBehavior = serverTimestampBehavior_,
1678-
metadataChanges](const firebase::firestore::DocumentSnapshot& snapshot,
1679-
firebase::firestore::Error error,
1680-
const std::string& errorMessage) mutable {
1663+
[this, serverTimestampBehavior = serverTimestampBehavior_](
1664+
const firebase::firestore::DocumentSnapshot& snapshot,
1665+
firebase::firestore::Error error,
1666+
const std::string& errorMessage) mutable {
16811667
if (error == firebase::firestore::kErrorOk) {
1682-
events_->Success(
1683-
ParseDocumentSnapshot(snapshot, serverTimestampBehavior)
1684-
.ToEncodableList());
1668+
// Emit the Pigeon object directly so the Pigeon-aware codec on
1669+
// the EventChannel serializes it end-to-end. Pigeon 26 no longer
1670+
// flattens nested types, so sending a raw list here would cause
1671+
// the Dart side to receive a List<Object?> it can no longer
1672+
// decode into InternalDocumentSnapshot.
1673+
events_->Success(CustomEncodableValue(
1674+
ParseDocumentSnapshot(snapshot, serverTimestampBehavior)));
16851675
} else {
16861676
EncodableMap details;
16871677
details[EncodableValue("code")] =

0 commit comments

Comments
 (0)