Skip to content

Commit 3f6bf6d

Browse files
trotylbenlesh
authored andcommitted
fix(common): properly check NaN value (#22305)
closes #15721 PR Close #22305
1 parent c3c0df9 commit 3f6bf6d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/common/src/pipes/async_pipe.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ChangeDetectorRef, EventEmitter, Injectable, OnDestroy, Pipe, PipeTransform, WrappedValue, ɵisObservable, ɵisPromise} from '@angular/core';
9+
import {ChangeDetectorRef, EventEmitter, Injectable, OnDestroy, Pipe, PipeTransform, WrappedValue, ɵisObservable, ɵisPromise, ɵlooseIdentical} from '@angular/core';
1010
import {Observable, SubscriptionLike} from 'rxjs';
1111
import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
1212

@@ -103,7 +103,7 @@ export class AsyncPipe implements OnDestroy, PipeTransform {
103103
return this.transform(obj as any);
104104
}
105105

106-
if (this._latestValue === this._latestReturnedValue) {
106+
if (ɵlooseIdentical(this._latestValue, this._latestReturnedValue)) {
107107
return this._latestReturnedValue;
108108
}
109109

packages/common/test/pipes/async_pipe_spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ import {SpyChangeDetectorRef} from '../spies';
8282
async.done();
8383
}, 10);
8484
}));
85+
86+
it('should return unwrapped value for unchanged NaN', () => {
87+
const emitter = new EventEmitter<any>();
88+
emitter.emit(null);
89+
pipe.transform(emitter);
90+
emitter.next(NaN);
91+
const firstResult = pipe.transform(emitter);
92+
const secondResult = pipe.transform(emitter);
93+
expect(firstResult instanceof WrappedValue).toBe(true);
94+
expect((firstResult as WrappedValue).wrapped).toBeNaN();
95+
expect(secondResult).toBeNaN();
96+
});
8597
});
8698

8799
describe('ngOnDestroy', () => {

0 commit comments

Comments
 (0)