fix(reactivity): ensure readonly on plain arrays doesn't track array methods. (#2506)
fix #2493
This commit is contained in:
parent
53f4885d9e
commit
34703082fd
@ -375,6 +375,16 @@ describe('reactivity/readonly', () => {
|
|||||||
expect(dummy).toBe(1)
|
expect(dummy).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('readonly array should not track', () => {
|
||||||
|
const arr = [1]
|
||||||
|
const roArr = readonly(arr)
|
||||||
|
|
||||||
|
const eff = effect(() => {
|
||||||
|
roArr.includes(2)
|
||||||
|
})
|
||||||
|
expect(eff.deps.length).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
test('readonly should track and trigger if wrapping reactive original (collection)', () => {
|
test('readonly should track and trigger if wrapping reactive original (collection)', () => {
|
||||||
const a = reactive(new Map())
|
const a = reactive(new Map())
|
||||||
const b = readonly(a)
|
const b = readonly(a)
|
||||||
|
@ -83,7 +83,8 @@ function createGetter(isReadonly = false, shallow = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const targetIsArray = isArray(target)
|
const targetIsArray = isArray(target)
|
||||||
if (targetIsArray && hasOwn(arrayInstrumentations, key)) {
|
|
||||||
|
if (!isReadonly && targetIsArray && hasOwn(arrayInstrumentations, key)) {
|
||||||
return Reflect.get(arrayInstrumentations, key, receiver)
|
return Reflect.get(arrayInstrumentations, key, receiver)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user