Skip to content

Commit

Permalink
fix(reactivity): assigning array.length while observing a symbol prop…
Browse files Browse the repository at this point in the history
…erty (#7568)
  • Loading branch information
skirtles-code authored Oct 21, 2023
1 parent a09ed44 commit e9e2778
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions packages/reactivity/__tests__/effect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,22 @@ describe('reactivity/effect', () => {
expect(dummy).toBe(undefined)
})

it('should support manipulating an array while observing symbol keyed properties', () => {
const key = Symbol()
let dummy
const array: any = reactive([1, 2, 3])
effect(() => (dummy = array[key]))

expect(dummy).toBe(undefined)
array.pop()
array.shift()
array.splice(0, 1)
expect(dummy).toBe(undefined)
array[key] = 'value'
array.length = 0
expect(dummy).toBe('value')
})

it('should observe function valued properties', () => {
const oldFunc = () => {}
const newFunc = () => {}
Expand Down
4 changes: 2 additions & 2 deletions packages/reactivity/src/effect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TrackOpTypes, TriggerOpTypes } from './operations'
import { extend, isArray, isIntegerKey, isMap } from '@vue/shared'
import { extend, isArray, isIntegerKey, isMap, isSymbol } from '@vue/shared'
import { EffectScope, recordEffectScope } from './effectScope'
import {
createDep,
Expand Down Expand Up @@ -324,7 +324,7 @@ export function trigger(
} else if (key === 'length' && isArray(target)) {
const newLength = Number(newValue)
depsMap.forEach((dep, key) => {
if (key === 'length' || key >= newLength) {
if (key === 'length' || (!isSymbol(key) && key >= newLength)) {
deps.push(dep)
}
})
Expand Down

0 comments on commit e9e2778

Please sign in to comment.