Skip to content Skip to sidebar Skip to footer

Firebase - How To Detect Where The Onsnapshot Is Coming From

I'm building a simple firebase app. The main textarea is linked to an entry on Firebase. When the user types, I debounce the keyup event (300ms) and I do an update on Firebase. Eve

Solution 1:

This is because the contents of the written document may be different than what the user has typed in since the document was updated.

Rethink this code:

doc.onSnapshot(function(doc){
    textareaElement.value = doc.data().text
});

This is going to overwrite whatever the user has typed since the debounce triggered and the document was updated with their progress. It will be especially painful on networks with high latency.

Consider instead not rewriting the entire textarea on each document change, and instead showing an indicator for the sync status of their typing. Is their typing in sync or not? That's all the user needs to know. You don't need to overwrite their typing on a regular basis.

Post a Comment for "Firebase - How To Detect Where The Onsnapshot Is Coming From"