-
Notifications
You must be signed in to change notification settings - Fork 989
Closed
Description
[REQUIRED] Describe your environment
- Operating System version: Ubuntu 22.04
- Browser version: Vivaldi 64 Bit 5.7.2921.65
- Firebase SDK version: 9.17.1
- Firebase Product: firestore
[REQUIRED] Describe the problem
When I modify data inside FirestoreDataConverter.toFirestore(), the source data is also modified, this causes error. Of course this could be fixed if I deep-copied the data first, but it's much simpler if the library handles this.
Steps to reproduce:
- Create an object to be sent to firestore
- Send the data/object to Firestore by calling
set()on a document reference that have converter - Modify the data inside converter's
toFirestore(). For example: assignserverTimeStampor delete unneded field. - The source data would also be modified
Relevant Code:
export const salesConverter: FirestoreDataConverter<Sales> = {
// this passed `data` should be deep copied so that it doesn't affect the original data
toFirestore(data: PartialWithFieldValue<Sales>, options?: SetOptions): DocumentData {
delete data.id
if (!data.createdAt) data.createdAt = serverTimestamp()
return data
},
fromFirestore(snap: QueryDocumentSnapshot, options: SnapshotOptions | undefined): Sales {
// ....
}
}