title: Firestore ArrayUnion Adds Duplicates
body: <p>I am using Firestore to store array of messages in a chat app.  For each message send, I update my message array with "arrayUnion." On update, sometimes two items will be added (to the client DB, and quickly be overriden by server)</p>
  
  <p>From <a href="https://firebase.google.com/docs/firestore/manage-data/add-data" rel="nofollow noreferrer">the docs</a>: "arrayUnion() adds elements to an array but only elements not already present". However, my case I see that my client Firebase DB instance will add duplicate data, and then the server will correct this upon successful write, and dedup.</p>
  
  <pre><code>  db.update({
      messages: firebase.firestore.FieldValue.arrayUnion(serverMessage)
    })
  </code></pre>
  
  <p>For ~1 second, I have duplicate items in arrays. I'm not sure why my data is being duplicated (I have validated that I only have one listener on the client) --- but I also don't understand why the client Firebase db instance allows for the duplicate write.  Here's a <a href="https://i.stack.imgur.com/UWYVL.png" rel="nofollow noreferrer">visual</a> of the errors I'm seeing.</p>