Firebase docData stream emits identical object values multiple times in a row

Discussão em 'Angular' iniciado por frontend-ux-ui, Setembro 12, 2024.

  1. This is my code:

    import { doc, docData } from '@angular/fire/firestore';

    const gameDocRef = doc(this.firestore, 'game', game.id);
    const game$ = docData(gameDocRef, { idField: 'id' })


    Somehow the game$ observable emits two identical emissions in a row

    Some things to note:

    • I am logging and checking: the stream only gets created once
    • I am logging and checking: the same exact deep-copy object gets emitted two times
    • I am only doing a single request to my firestore-backend and yet this request causes two identical emissions

    Of course I could do a distinctUntilXChanged on the observable, but afaik this will still count them as two distinct reads in my firestore quota. This is the main problem I am trying to avoid, I do not want to pay twice as much money for firestore than I actually need to.

    This is how I am determining whether the emissions are identical:

    const currentGameJSON = JSON.stringify(currentGame);
    const newGameJSON = JSON.stringify(game);
    if (currentGameJSON === newGameJSON) {
    console.error("SAME GAME EMISSION", currentGameJSON);
    }


    My doc does not have recursive props or anything weird like this, simple JSON.

    I do not have firestore persistence enabled.

    Continue reading...

Compartilhe esta Página