Skip to content

Commit c1bf20a

Browse files
committed
do not trigger change on NaN->NaN set (fix vuejs#4236)
1 parent 9a742cb commit c1bf20a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/core/observer/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export function defineReactive (
162162
},
163163
set: function reactiveSetter (newVal) {
164164
const value = getter ? getter.call(obj) : val
165-
if (newVal === value) {
165+
if (newVal === value || (newVal !== newVal && value !== value)) {
166166
return
167167
}
168168
if (process.env.NODE_ENV !== 'production' && customSetter) {

test/unit/modules/observer/observer.spec.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ describe('Observer', () => {
177177
})
178178

179179
it('observing object prop change', () => {
180-
const obj = { a: { b: 2 }}
180+
const obj = { a: { b: 2 }, c: NaN }
181181
observe(obj)
182182
// mock a watcher!
183183
const watcher = {
@@ -192,20 +192,25 @@ describe('Observer', () => {
192192
Dep.target = watcher
193193
obj.a.b
194194
Dep.target = null
195-
expect(watcher.deps.length).toBe(3) // obj.a + a.b + b
195+
expect(watcher.deps.length).toBe(3) // obj.a + a + a.b
196196
obj.a.b = 3
197197
expect(watcher.update.calls.count()).toBe(1)
198198
// swap object
199199
obj.a = { b: 4 }
200200
expect(watcher.update.calls.count()).toBe(2)
201201
watcher.deps = []
202+
202203
Dep.target = watcher
203204
obj.a.b
205+
obj.c
204206
Dep.target = null
205-
expect(watcher.deps.length).toBe(3)
207+
expect(watcher.deps.length).toBe(4)
206208
// set on the swapped object
207209
obj.a.b = 5
208210
expect(watcher.update.calls.count()).toBe(3)
211+
// should not trigger on NaN -> NaN set
212+
obj.c = NaN
213+
expect(watcher.update.calls.count()).toBe(3)
209214
})
210215

211216
it('observing object prop change on defined property', () => {

0 commit comments

Comments
 (0)