Skip to content

Commit ba59a0f

Browse files
Return Firestore Classic types from Transaction API (#4233)
1 parent dec74aa commit ba59a0f

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

.changeset/slimy-mugs-type.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/firestore": patch
3+
---
4+
5+
Fixes an issue in the Transaction API that caused the SDK to return invalid DocumentReferences through `DocumentSnapshot.data()` calls.

packages/firestore/src/api/database.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,14 @@ export function setLogLevel(level: PublicLogLevel): void {
406406
export class Transaction
407407
extends Compat<ExpTransaction>
408408
implements PublicTransaction {
409+
private _userDataWriter: UserDataWriter;
410+
409411
constructor(
410412
private readonly _firestore: Firestore,
411413
delegate: ExpTransaction
412414
) {
413415
super(delegate);
416+
this._userDataWriter = new UserDataWriter(_firestore);
414417
}
415418

416419
get<T>(
@@ -419,7 +422,20 @@ export class Transaction
419422
const ref = castReference(documentRef);
420423
return this._delegate
421424
.get(ref)
422-
.then(result => new DocumentSnapshot(this._firestore, result));
425+
.then(
426+
result =>
427+
new DocumentSnapshot(
428+
this._firestore,
429+
new ExpDocumentSnapshot<T>(
430+
this._firestore._delegate,
431+
this._userDataWriter,
432+
result._key,
433+
result._document,
434+
result.metadata,
435+
ref._converter
436+
)
437+
)
438+
);
423439
}
424440

425441
set<T>(

packages/firestore/test/integration/api/type.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ apiDescribe('Firestore', (persistence: boolean) => {
4242
let docSnapshot = await doc.get();
4343
expect(docSnapshot.data()).to.deep.equal(data);
4444

45+
// Validate that the transaction API returns the same types
46+
await db.runTransaction(async transaction => {
47+
docSnapshot = await transaction.get(doc);
48+
expect(docSnapshot.data()).to.deep.equal(data);
49+
});
50+
4551
if (validateSnapshots) {
4652
let querySnapshot = await collection.get();
4753
docSnapshot = querySnapshot.docs[0];

0 commit comments

Comments
 (0)