From 947bf6ce8b9001c7e73405d8649c7642b6a4f58a Mon Sep 17 00:00:00 2001 From: yeyuqiudeng Date: Fri, 28 Aug 2020 20:09:21 +0800 Subject: [PATCH] fix(reactivity): add NaN prop on Array should not trigger length dependency. --- packages/reactivity/__tests__/reactiveArray.spec.ts | 2 ++ packages/shared/src/index.ts | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/reactivity/__tests__/reactiveArray.spec.ts b/packages/reactivity/__tests__/reactiveArray.spec.ts index 0ab458d34f1..170cb1b39c1 100644 --- a/packages/reactivity/__tests__/reactiveArray.spec.ts +++ b/packages/reactivity/__tests__/reactiveArray.spec.ts @@ -124,6 +124,8 @@ describe('reactivity/reactive/Array', () => { expect(fn).toHaveBeenCalledTimes(1) observed[-1] = 'x' expect(fn).toHaveBeenCalledTimes(1) + observed[NaN] = 'x' + expect(fn).toHaveBeenCalledTimes(1) }) describe('Array methods w/ refs', () => { diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index 69739cae251..caae762ab7e 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -82,7 +82,10 @@ export const isPlainObject = (val: unknown): val is object => toTypeString(val) === '[object Object]' export const isIntegerKey = (key: unknown) => - isString(key) && key[0] !== '-' && '' + parseInt(key, 10) === key + isString(key) && + key !== 'NaN' && + key[0] !== '-' && + '' + parseInt(key, 10) === key export const isReservedProp = /*#__PURE__*/ makeMap( 'key,ref,' +