Skip to content

Commit 9cc45a1

Browse files
author
Brian Chen
committed
use docref constructor instead of defaultconverter
1 parent 655dab8 commit 9cc45a1

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

.changeset/tame-donuts-relate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'@firebase/firestore': patch
33
---
44

5-
Fixed a bug that where CollectionReference.add() called FirestoreDataConverter.toFirestore() twice intead of once (#3742).
5+
Fixed a bug where CollectionReference.add() called FirestoreDataConverter.toFirestore() twice intead of once (#3742).

packages/firestore/src/api/database.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,21 +2380,15 @@ export class CollectionReference<T = DocumentData>
23802380
: value;
23812381
validateArgType('CollectionReference.add', 'object', 1, convertedValue);
23822382

2383-
// Call set() with the converted value directly to avoid calling toFirestore() a second time.
23842383
const docRef = this.doc();
2385-
const defaultConverter: FirestoreDataConverter<DocumentData> = {
2386-
toFirestore(modelObject: DocumentData): DocumentData {
2387-
return modelObject;
2388-
},
2389-
fromFirestore(
2390-
snapshot: QueryDocumentSnapshot,
2391-
options: SnapshotOptions
2392-
): DocumentData {
2393-
return snapshot.data(options)!;
2394-
}
2395-
};
2396-
return docRef
2397-
.withConverter(defaultConverter)
2384+
2385+
// Call set() with the converted value directly to avoid calling toFirestore() a second time.
2386+
// Cast to unknown in order to access the _key property.
2387+
return new DocumentReference(
2388+
((docRef as unknown) as DocumentReference)._key,
2389+
this.firestore,
2390+
null
2391+
)
23982392
.set(convertedValue)
23992393
.then(() => docRef);
24002394
}

0 commit comments

Comments
 (0)