Alex
Alex

Reputation: 397

firebase 8.4 runs .once() repeatedly

My applications runs well in [email protected]. On 8.4.0/1/2/3, the .once() code is executed repeatedly, indefinitely.

my code:

public buStateClick(key: string, action: state) {
    this._afDB.database.ref(`${path}/${key}/state`).once('value', (snap) => {
      this._afDB.database.ref(`${path}/${key}/state`).off(); // required after 8.4.0
      if (snap.exists()) {
        this._afDB.database.ref(`${path}/${key}`).update({state: newState});
      }
    });
}

In my original program without the .off(), when the code runs, the .once() and .update() were executed >700 times until the stack fails. Adding .off() reverts it back to its original behaviour.

I believe that .once() is supposed to .off() itself, and should never run more than once. There is no reason the code needs an .off() to work.

reference: my original question firebase 8.4 makes my .once() keep firing [was: firebase 8.4 makes my onclick event keep firing]

@NickArmitage has a similar problem but his code only works up to 8.3.2.

Upvotes: 1

Views: 66

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

firebaser here

This is indeed a regression in the 8.4 version of the SDK. Thanks for the clear MCVE, which I was able to reproduce with the JSBin that I linked in my comment above.

The bug was also recorded on the Github repo for the SDK, and a fix is in the works. Keep an eye out on the issue to catch any updates.

Upvotes: 1

Related Questions