angular / angularfire

Angular + Firebase = ❤️
https://firebaseopensource.com/projects/angular/angularfire2
MIT License
7.64k stars 2.2k forks source link

AngularFireUploadTask snapshot state doesn't change upon cancellation - AngularFireStorage #1805

Closed yuliankarapetkov closed 3 years ago

yuliankarapetkov commented 5 years ago

Version info

Angular: 6.03

Firebase: 5.2.0

AngularFire: 5.0.0-rc.11

How to reproduce these conditions

Steps to set up and reproduce

Subscribe to snapshotChanges and log the value of the snapshot. Cancel the AngularFireUploadTask through the cancel() method. Snapshot doesn't change => snapshot.state === 'running', instead of snapshot.state === 'cancelled'

Expected behavior

snapshot has a new value with state === 'cancelled'

Actual behavior

snapshot doesn't have a new value, so state === 'running'

davideast commented 5 years ago

@yuliankarapetkov Can you create a stackblitz for me to debug?

yuliankarapetkov commented 5 years ago

@davideast Hey, thanks for looking into this for me.

Here's a stackblitz link

UPDATE: Just noticed that state doesn't change at all, even if the upload has actually been successful. However, the snapshot embedded task object has the correct state, so I guess that this is really a bug.

See screenshot: https://imgur.com/HixmZ2T

yuliankarapetkov commented 5 years ago

@davideast did you get the chance to check the stackblitz link provided?

alexdabast commented 5 years ago

Seems to be a real bug The last event is not emitted on the snapshotChanges() however it will be emitted in the .then() promise

this._task.snapshotChanges()
  .subscribe(snapshot => {
    this.snapshot = snapshot; // To get updates on progress
  });
this._task.then(snapshot => {
  this.snapshot = snapshot; // To know when it is done
}).catch(snapshot => {
  this.snapshot = this._task.task.snapshot; // To know whenever there is an error/cancel from user
});
jamesdaniels commented 3 years ago

Both of these issues should have been addressed in a recent 6.0 patch, we were not updating the taskSnapshot on completion just completing the observable. Similarly I realized error wasn't updating the snapshot and have made a PR for that #2665 which will be in 6.1.1