@@ -300,16 +300,19 @@ export class LocalStore {
300
300
documentKeySet ( )
301
301
) ;
302
302
303
- return this . persistence . runTransaction (
304
- 'Locally write mutations' ,
305
- 'readwrite' ,
306
- txn => {
307
- // Load and apply all existing mutations. This lets us compute the
308
- // current base state for all non-idempotent transforms before applying
309
- // any additional user-provided writes.
310
- return this . localDocuments
311
- . getDocuments ( txn , keys )
312
- . next ( existingDocs => {
303
+ let existingDocs : MaybeDocumentMap ;
304
+
305
+ return this . persistence
306
+ . runTransaction (
307
+ 'Locally write mutations' ,
308
+ 'readwrite-idempotent' ,
309
+ txn => {
310
+ // Load and apply all existing mutations. This lets us compute the
311
+ // current base state for all non-idempotent transforms before applying
312
+ // any additional user-provided writes.
313
+ return this . localDocuments . getDocuments ( txn , keys ) . next ( docs => {
314
+ existingDocs = docs ;
315
+
313
316
// For non-idempotent mutations (such as `FieldValue.increment()`),
314
317
// we record the base state in a separate patch mutation. This is
315
318
// later used to guarantee consistent values and prevents flicker
@@ -336,15 +339,19 @@ export class LocalStore {
336
339
}
337
340
}
338
341
339
- return this . mutationQueue
340
- . addMutationBatch ( txn , localWriteTime , baseMutations , mutations )
341
- . next ( batch => {
342
- const changes = batch . applyToLocalDocumentSet ( existingDocs ) ;
343
- return { batchId : batch . batchId , changes } ;
344
- } ) ;
342
+ return this . mutationQueue . addMutationBatch (
343
+ txn ,
344
+ localWriteTime ,
345
+ baseMutations ,
346
+ mutations
347
+ ) ;
345
348
} ) ;
346
- }
347
- ) ;
349
+ }
350
+ )
351
+ . then ( batch => {
352
+ const changes = batch . applyToLocalDocumentSet ( existingDocs ) ;
353
+ return { batchId : batch . batchId , changes } ;
354
+ } ) ;
348
355
}
349
356
350
357
/** Returns the local view of the documents affected by a mutation batch. */
0 commit comments