Skip to content

Commit

Permalink
fix(firestore): handle snapshot errors on web (#655)
Browse files Browse the repository at this point in the history
* fix(firestore): handle snapshot errors on web

* add the changeset

* Update itchy-cobras-hunt.md

---------

Co-authored-by: Robin Genz <[email protected]>
  • Loading branch information
mamillastre and robingenz authored Jun 27, 2024
1 parent ce5c1d4 commit 841d9d3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-cobras-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@capacitor-firebase/firestore': patch
---

fix(web): handle snapshot errors
49 changes: 29 additions & 20 deletions packages/firestore/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export class FirebaseFirestoreWeb
};
callback(event, undefined);
},
error => callback(null, error),
);
const id = Date.now().toString();
this.unsubscribesMap.set(id, unsubscribe);
Expand All @@ -237,16 +238,20 @@ export class FirebaseFirestoreWeb
options,
'collection',
);
const unsubscribe = onSnapshot(collectionQuery, snapshot => {
const event: AddCollectionSnapshotListenerCallbackEvent<T> = {
snapshots: snapshot.docs.map(documentSnapshot => ({
id: documentSnapshot.id,
path: documentSnapshot.ref.path,
data: documentSnapshot.data() as T,
})),
};
callback(event, undefined);
});
const unsubscribe = onSnapshot(
collectionQuery,
snapshot => {
const event: AddCollectionSnapshotListenerCallbackEvent<T> = {
snapshots: snapshot.docs.map(documentSnapshot => ({
id: documentSnapshot.id,
path: documentSnapshot.ref.path,
data: documentSnapshot.data() as T,
})),
};
callback(event, undefined);
},
error => callback(null, error),
);
const id = Date.now().toString();
this.unsubscribesMap.set(id, unsubscribe);
return id;
Expand All @@ -262,16 +267,20 @@ export class FirebaseFirestoreWeb
options,
'collectionGroup',
);
const unsubscribe = onSnapshot(collectionQuery, snapshot => {
const event: AddCollectionSnapshotListenerCallbackEvent<T> = {
snapshots: snapshot.docs.map(documentSnapshot => ({
id: documentSnapshot.id,
path: documentSnapshot.ref.path,
data: documentSnapshot.data() as T,
})),
};
callback(event, undefined);
});
const unsubscribe = onSnapshot(
collectionQuery,
snapshot => {
const event: AddCollectionSnapshotListenerCallbackEvent<T> = {
snapshots: snapshot.docs.map(documentSnapshot => ({
id: documentSnapshot.id,
path: documentSnapshot.ref.path,
data: documentSnapshot.data() as T,
})),
};
callback(event, undefined);
},
error => callback(null, error),
);
const id = Date.now().toString();
this.unsubscribesMap.set(id, unsubscribe);
return id;
Expand Down

0 comments on commit 841d9d3

Please sign in to comment.