Skip to content

Commit a88f706

Browse files
committed
fix: when value is NaN, will enter a infinite loop
1 parent 470d517 commit a88f706

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/behavior.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ enum ComputedWatchInitStatus {
3737

3838
let computedWatchDefIdInc = 0
3939

40+
function equal(a: unknown, b: unknown) {
41+
if (a === b) {
42+
return true
43+
} else {
44+
// When a = b = NaN
45+
// NaN === NaN is false
46+
return a !== a && b !== b
47+
}
48+
}
49+
4050
export const behavior = Behavior({
4151
lifetimes: {
4252
attached(this: BehaviorExtend) {
@@ -117,7 +127,7 @@ export const behavior = Behavior({
117127
for (let i = 0; i < oldPathValues.length; i++) {
118128
const { path, value: oldVal } = oldPathValues[i]
119129
const curVal = dataPath.getDataOnPath(this.data, path)
120-
if (oldVal !== curVal) {
130+
if (!equal(oldVal, curVal)) {
121131
needUpdate = true
122132
break
123133
}
@@ -220,7 +230,7 @@ export const behavior = Behavior({
220230
if (
221231
deepCmp
222232
? !deepEqual(oldVal[i], curVal[i])
223-
: oldVal[i] !== curVal[i]
233+
: !equal(oldVal[i], curVal[i])
224234
) {
225235
changed = true
226236
break

0 commit comments

Comments
 (0)