Skip to content

Commit

Permalink
fix: added check for no query results
Browse files Browse the repository at this point in the history
  • Loading branch information
puppybits committed Nov 19, 2021
1 parent 7f24eff commit d0d52b3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/utils/mutate.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const isDocRead = ({ doc, id } = {}) =>
const isProviderRead = (read) => isFunction(read);
const isSingleWrite = ({ collection, path } = {}) =>
typeof path === 'string' || typeof collection === 'string';
const hasNothing = (snapshot) =>
!snapshot ||
(snapshot.empty && snapshot.empty()) ||
(snapshot.exists && snapshot.exists());

// ----- FieldValue support -----

Expand Down Expand Up @@ -182,7 +186,7 @@ async function writeInTransaction(firebase, operations) {
// else query (As of 7/2021, Firestore doesn't include queries in client-side transactions)
const coll = firestoreRef(firebase, read);
const snapshot = await coll.get();
if (snapshot.docs.length === 0) return [];
if (hasNothing(snapshot) || snapshot.docs.length === 0) return [];
const unserializedDocs = await Promise.all(snapshot.docs.map(getter));
return unserializedDocs.map(serialize);
});
Expand Down

0 comments on commit d0d52b3

Please sign in to comment.