-
Notifications
You must be signed in to change notification settings - Fork 985
Closed
Labels
Description
When using .set, .update on DocumentReference, we can directly do a .get after without risking invalid data in the "local database".
But since WriteBatch.commit is written as an AsyncFunction, it defers the commit to the "local database" to the next event loop.
I'm not sure wherever the original use case is supported, but it'd be great to have consistency between those methods. I've spent some time debugging a timing issue in my React application with a code like (where the navigate cause a read-sync in and use a suspense firestore cache):
const batch = firestore().batch();
const post = ...
batch.set(...)
batch.commit(); // The changes will no be applied in the local firestore before after the call to navigate.
navigate(`post/${post.id}`);While it'll work with:
const post ...
firebase.firestore().collection('posts').doc(post.id).set(post)
navigate(`post/${post.id}`);