@@ -29,6 +29,13 @@ import { onSnapshot } from 'firebase/firestore'
29
29
* Options when binding a Firestore document or collection.
30
30
*/
31
31
export interface FirestoreRefOptions extends _DataSourceOptions {
32
+ /**
33
+ * Ignores snapshot changes that are coming from the Firestore client cache, defering ref updates until fresh data
34
+ * is pulled from the server. Useful for pagination scenarios, when using multiple listeners on the same collection
35
+ * with distinct queries and updating query refs.
36
+ */
37
+ ignoreCachedChanges ?: boolean
38
+
32
39
/**
33
40
* The maximum depth to bind nested refs. A nested ref that isn't bound will stay as the ref path while a bound ref
34
41
* will contain the same data as if the ref was bound directly.
@@ -60,11 +67,17 @@ export interface _FirestoreRefOptionsWithDefaults extends FirestoreRefOptions {
60
67
* @defaultValue `false`
61
68
*/
62
69
reset : ResetOption
70
+
63
71
/**
64
72
* @defaultValue `true`
65
73
*/
66
74
wait : boolean
67
75
76
+ /**
77
+ * @defaultValue `false`
78
+ */
79
+ ignoreCachedChanges : boolean
80
+
68
81
/**
69
82
* @defaultValue `2`
70
83
*/
@@ -88,6 +101,7 @@ export interface _FirestoreRefOptionsWithDefaults extends FirestoreRefOptions {
88
101
const DEFAULT_OPTIONS : _FirestoreRefOptionsWithDefaults = {
89
102
reset : false ,
90
103
wait : true ,
104
+ ignoreCachedChanges : false ,
91
105
maxRefDepth : 2 ,
92
106
converter : firestoreDefaultConverter ,
93
107
snapshotOptions : { serverTimestamps : 'estimate' } ,
@@ -380,8 +394,10 @@ export function bindCollection<T = unknown>(
380
394
// (https://firebase.google.com/docs/firestore/query-data/listen#view_changes_between_snapshots)
381
395
382
396
const docChanges = snapshot . docChanges ( snapshotListenOptions )
397
+ const ignoreCached : boolean =
398
+ options . ignoreCachedChanges && snapshot . metadata . fromCache
383
399
384
- if ( ! isResolved && docChanges . length ) {
400
+ if ( ! isResolved && docChanges . length && ! ignoreCached ) {
385
401
// isResolved is only meant to make sure we do the check only once
386
402
isResolved = true
387
403
let count = 0
0 commit comments