Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(firestore,windows): fix an issue that could happen when querying …
…by DocumentReference value
  • Loading branch information
Lyokone committed Mar 3, 2026
commit b27a919a37f500e69b0a8b7200abd78b77f90ae5
Original file line number Diff line number Diff line change
Expand Up @@ -629,5 +629,39 @@ void runDocumentReferenceTests() {
timeout: const Timeout.factor(3),
);
});

group('DocumentReference as field value', () {
// Regression test for https://github.com/firebase/flutterfire/issues/18028
test('can store and read a DocumentReference as a field value', () async {
final doc = await initializeTest('doc-ref-field');
final targetDoc = firestore.doc('flutter-tests/target-doc');

await doc.set({'ref': targetDoc});

final snapshot = await doc.get();
final refValue = snapshot.data()!['ref'];
expect(refValue, isA<DocumentReference>());
expect((refValue as DocumentReference).path, targetDoc.path);
});

test('can query by DocumentReference value', () async {
final collection =
firestore.collection('flutter-tests/doc-ref-query/items');
final targetDoc = firestore.doc('flutter-tests/target-doc');

// Clean up
final existing = await collection.get();
for (final doc in existing.docs) {
await doc.reference.delete();
}

await collection.add({'ref': targetDoc, 'name': 'test'});

final querySnapshot =
await collection.where('ref', isEqualTo: targetDoc).get();
expect(querySnapshot.docs, hasLength(1));
expect(querySnapshot.docs.first.data()['name'], 'test');
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,24 @@ cloud_firestore_windows::FirestoreCodec::ReadValueOfType(
std::get<CustomEncodableValue>(
FirestoreCodec::ReadValue(stream)));

if (CloudFirestorePlugin::firestoreInstances_.find(appName) !=
// Use composite key matching GetFirestoreFromPigeon to avoid
// creating a duplicate unique_ptr for the same Firestore instance.
// See https://github.com/firebase/flutterfire/issues/18028
std::string cacheKey = appName + "-" + databaseUrl;

if (CloudFirestorePlugin::firestoreInstances_.find(cacheKey) !=
CloudFirestorePlugin::firestoreInstances_.end()) {
return CustomEncodableValue(
CloudFirestorePlugin::firestoreInstances_[appName].get());
CloudFirestorePlugin::firestoreInstances_[cacheKey].get());
}

firebase::App* app = firebase::App::GetInstance(appName.c_str());

Firestore* firestore = Firestore::GetInstance(app);
Firestore* firestore =
Firestore::GetInstance(app, databaseUrl.c_str());
firestore->set_settings(settings);

CloudFirestorePlugin::firestoreInstances_[appName] =
CloudFirestorePlugin::firestoreInstances_[cacheKey] =
std::unique_ptr<firebase::firestore::Firestore>(firestore);

return CustomEncodableValue(firestore);
Expand Down
Loading