From 9b0148ace5472ba9eda03855e15b0d819a168615 Mon Sep 17 00:00:00 2001 From: cassln Date: Wed, 12 Jul 2017 15:04:10 +0300 Subject: [PATCH] Fix infinity rerender with NaN value --- src/utils.js | 4 +++- tests/Utils-spec.js | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index f8b94a3c..3270c303 100644 --- a/src/utils.js +++ b/src/utils.js @@ -36,7 +36,9 @@ module.exports = { return a.toString() === b.toString(); } else if (typeof a === 'object' && a !== null && b !== null) { return !this.objectsDiffer(a, b); - } + } else if (typeof a === 'number' && isNaN(a) && isNaN(b)) { + return true; + } return a === b; }, diff --git a/tests/Utils-spec.js b/tests/Utils-spec.js index 1437ab91..63f4849b 100644 --- a/tests/Utils-spec.js +++ b/tests/Utils-spec.js @@ -12,6 +12,8 @@ export default { const objF = undefined; const objG = null; const objH = null; + const objI = NaN; + const objJ = NaN; test.equal(utils.isSame(objA, objB), true); test.equal(utils.isSame(objC, objD), true); @@ -26,6 +28,11 @@ export default { test.equal(utils.isSame(objC, objH), false); test.equal(utils.isSame(objG, objA), false); + test.equal(utils.isSame(objI, objJ), true); + test.equal(utils.isSame(objA, objJ), false); + test.equal(utils.isSame(objC, objJ), false); + test.equal(utils.isSame(objI, objA), false); + test.equal(utils.isSame(() => {}, () => {}), true); test.equal(utils.isSame(objA, () => {}), false); test.equal(utils.isSame(() => {}, objA), false);