Description
I'm experiencing a reproducible change detection issue with [email protected]
, where the first emissions from snapshotChanges()
and valueChanges()
are not triggering Angular change detection appropriately.
https://stackblitz.com/edit/angular-nkqyhq
As demonstrated in the StackBlitz example above, the first values emitted by AngularFireDatabase valueChanges()
Observables are being populated as expected, but UI is not redrawing automatically (unless triggered manually, or by something else). Subsequent valueChanges()
emissions appear to trigger change detection as expected, reproducible in the above example by navigating away from and back to the example routed component.
This issue first appears with the merging of #1454 (commit e343f13).
I haven't had a chance to dig into it, but this behavior appears to be related to the new FirebaseZoneScheduler
; the current implementation of the keepUnstableUntilFirst()
method in particular has me a bit puzzled.
https://github.com/angular/angularfire2/blob/master/src/core/angularfire2.ts#L25-L33
Version info
Angular: 5.2.10
% ng --version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 1.7.4
Node: 9.11.1
OS: darwin x64
Angular: 5.2.10
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cdk: 5.2.5
@angular/cli: 1.7.4
@angular/flex-layout: 5.0.0-beta.14
@angular/material: 5.2.5
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.6.2
webpack-bundle-analyzer: 2.11.1
webpack: 3.11.0
Firebase: 4.12.1
AngularFire: 5.0.0-rc.7.0-next
Browser: Chrome OS v66.0.3359.139
Operating system: macOS Sierra v10.12.6
How to reproduce these conditions
Failing test unit, Plunkr, or JSFiddle demonstrating the problem
https://stackblitz.com/edit/angular-nkqyhq
Steps to set up and reproduce
- Create a component which injects
AngularFireDatabase
- Subscribe to
valueChanges()
Observable - Interpolate value change in template (will not display first result from Observable)
Debug output
** Errors in the JavaScript console **
None.
** Output from firebase.database().enableLogging(true);
**
Not sure how to enable this.
** Screenshots **
N/A
Expected behavior
First value emitted from AngularFireDatabase.valueChanges()
Observable consistently triggers change detection.
Actual behavior
First value emitted from AngularFireDatabase.valueChanges()
Observable does not consistently trigger change detection.