@@ -516,21 +516,32 @@ export class LocalStore {
516
516
documentBuffer . getEntries ( txn , updatedKeys ) . next ( existingDocs => {
517
517
remoteEvent . documentUpdates . forEach ( ( key , doc ) => {
518
518
const existingDoc = existingDocs . get ( key ) ;
519
+
520
+ // Note: The order of the steps below is important, since we want
521
+ // to ensure that rejected limbo resolutions (which fabricate
522
+ // NoDocuments with SnapshotVersion.NONE) never add documents to
523
+ // cache.
519
524
if (
520
- existingDoc == null ||
521
- doc . version . compareTo ( existingDoc . version ) > 0 ||
522
- ( doc . version . compareTo ( existingDoc . version ) === 0 &&
523
- existingDoc . hasPendingWrites )
525
+ doc instanceof NoDocument &&
526
+ doc . version . isEqual ( SnapshotVersion . MIN )
524
527
) {
528
+ // NoDocuments with SnapshotVersion.MIN are used in manufactured
529
+ // events. We remove these documents from cache since we lost
530
+ // access.
525
531
documentBuffer . addEntry ( doc ) ;
526
532
changedDocs = changedDocs . insert ( key , doc ) ;
527
533
} else if (
528
- doc instanceof NoDocument &&
529
- doc . version . isEqual ( SnapshotVersion . MIN )
534
+ existingDoc == null ||
535
+ doc . version . compareTo ( existingDoc . version ) > 0 ||
536
+ ( doc . version . compareTo ( existingDoc . version ) === 0 &&
537
+ existingDoc . hasPendingWrites )
530
538
) {
531
- // NoDocuments with SnapshotVersion.MIN are used in manufactured events (e.g. in the
532
- // case of a limbo document resolution failing). We remove these documents from cache
533
- // since we lost access.
539
+ // TODO(index-free): Comment in this assert when we enable
540
+ // Index-Free queries
541
+ // assert(
542
+ // !SnapshotVersion.MIN.isEqual(remoteEvent.snapshotVersion),
543
+ // 'Cannot add a document when the remote version is zero'
544
+ // );
534
545
documentBuffer . removeEntry ( key ) ;
535
546
changedDocs = changedDocs . insert ( key , doc ) ;
536
547
} else {
0 commit comments