Skip to content

Commit a306658

Browse files
committed
fix(reactivity): should not trigger length dependency on Array delete
close #774
1 parent 689d45f commit a306658

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/reactivity/__tests__/reactiveArray.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ describe('reactivity/reactive/Array', () => {
8888
expect(index).toBe(1)
8989
})
9090

91+
test('delete on Array should not trigger length dependency', () => {
92+
const arr = reactive([1, 2, 3])
93+
const fn = jest.fn()
94+
effect(() => {
95+
fn(arr.length)
96+
})
97+
expect(fn).toHaveBeenCalledTimes(1)
98+
delete arr[1]
99+
expect(fn).toHaveBeenCalledTimes(1)
100+
})
101+
91102
describe('Array methods w/ refs', () => {
92103
let original: any[]
93104
beforeEach(() => {

packages/reactivity/src/effect.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export function trigger(
196196
// also run for iteration key on ADD | DELETE | Map.SET
197197
if (
198198
type === TriggerOpTypes.ADD ||
199-
type === TriggerOpTypes.DELETE ||
199+
(type === TriggerOpTypes.DELETE && !isArray(target)) ||
200200
(type === TriggerOpTypes.SET && target instanceof Map)
201201
) {
202202
const iterationKey = isArray(target) ? 'length' : ITERATE_KEY

0 commit comments

Comments
 (0)