perf(reactivity): add existing index or non-integer prop on Array should not trigger length dependency (#1969)
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
isSymbol,
|
||||
hasChanged,
|
||||
isArray,
|
||||
isIntegerKey,
|
||||
extend
|
||||
} from '@vue/shared'
|
||||
import { isRef } from './ref'
|
||||
@@ -87,10 +88,7 @@ function createGetter(isReadonly = false, shallow = false) {
|
||||
|
||||
if (isRef(res)) {
|
||||
// ref unwrapping - does not apply for Array + integer key.
|
||||
const shouldUnwrap =
|
||||
!targetIsArray ||
|
||||
keyIsSymbol ||
|
||||
'' + parseInt(key as string, 10) !== key
|
||||
const shouldUnwrap = !targetIsArray || !isIntegerKey(key)
|
||||
return shouldUnwrap ? res.value : res
|
||||
}
|
||||
|
||||
@@ -126,7 +124,10 @@ function createSetter(shallow = false) {
|
||||
// in shallow mode, objects are set as-is regardless of reactive or not
|
||||
}
|
||||
|
||||
const hadKey = hasOwn(target, key)
|
||||
const hadKey =
|
||||
isArray(target) && isIntegerKey(key)
|
||||
? Number(key) < target.length
|
||||
: hasOwn(target, key)
|
||||
const result = Reflect.set(target, key, value, receiver)
|
||||
// don't trigger if target is something up in the prototype chain of original
|
||||
if (target === toRaw(receiver)) {
|
||||
|
||||
Reference in New Issue
Block a user