Skip to content

Commit fbfa24f

Browse files
committed
toJSON methods warn of pending writes.
1 parent e0f3c29 commit fbfa24f

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

packages/firestore/src/api/snapshot.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
QuerySnapshotBundleData
4343
} from '../util/bundle_builder_impl';
4444
import { Code, FirestoreError } from '../util/error';
45+
import { logWarn } from '../util/log';
4546
import { AutoId } from '../util/misc';
4647

4748
import { Firestore } from './database';
@@ -520,6 +521,11 @@ export class DocumentSnapshot<
520521
document.data.value.mapValue.fields,
521522
'previous'
522523
);
524+
if (documentData.hasPendingWrites) {
525+
logWarn(
526+
'DocumentSnapshot.toJSON serialized a document with pending writes. The pending writes will not be serialized.'
527+
);
528+
}
523529
builder.addBundleDocument(
524530
documentToDocumentSnapshotBundleData(
525531
this.ref.path,
@@ -703,6 +709,11 @@ export class QuerySnapshot<
703709
doc._document.data.value.mapValue.fields,
704710
'previous'
705711
);
712+
if (documentData.hasPendingWrites) {
713+
logWarn(
714+
'QuerySnapshot.toJSON serialized a document with pending writes. The pending writes will not be serialized.'
715+
);
716+
}
706717
docBundleDataArray.push(
707718
documentToDocumentSnapshotBundleData(
708719
doc.ref.path,

packages/firestore/src/util/bundle_builder_impl.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ export class BundleBuilder {
107107
: null;
108108

109109
const neitherHasReadTime: boolean = !docReadTime && origDocReadTime == null;
110-
const docIsNewer: boolean = docReadTime !== undefined && (origDocReadTime == null || origDocReadTime < docReadTime);
110+
const docIsNewer: boolean =
111+
docReadTime !== undefined &&
112+
(origDocReadTime == null || origDocReadTime < docReadTime);
111113
if (neitherHasReadTime || docIsNewer) {
112114
// Store document.
113115
this.documents.set(docBundleData.documentPath, {
@@ -120,7 +122,7 @@ export class BundleBuilder {
120122
exists: docBundleData.documentExists
121123
}
122124
});
123-
}
125+
}
124126
if (docReadTime && docReadTime > this.latestReadTime) {
125127
this.latestReadTime = docReadTime;
126128
}
@@ -176,12 +178,6 @@ export class BundleBuilder {
176178
private toBundleDocument(
177179
docBundleData: DocumentSnapshotBundleData
178180
): ProtoDocument {
179-
// TODO handle documents that have mutations
180-
debugAssert(
181-
!docBundleData.documentData.hasLocalMutations,
182-
"Can't serialize documents with mutations."
183-
);
184-
185181
// a parse context is typically used for validating and parsing user data, but in this
186182
// case we are using it internally to convert DocumentData to Proto3 JSON
187183
const context = this.userDataReader.createContext(

0 commit comments

Comments
 (0)