]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(reactivity): assigning array.length while observing a symbol property (#7568)
authorskirtle <65301168+skirtles-code@users.noreply.github.com>
Sat, 21 Oct 2023 01:48:59 +0000 (02:48 +0100)
committerGitHub <noreply@github.com>
Sat, 21 Oct 2023 01:48:59 +0000 (09:48 +0800)
packages/reactivity/__tests__/effect.spec.ts
packages/reactivity/src/effect.ts

index 635e6534abe5355d21a1244a0ac50baca508074a..e34c7b31e40ad4d59eb1e3b6c817baed65883c50 100644 (file)
@@ -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 = () => {}
index bbac96a4b2a0bc092b4ff15546eebcebf8943006..c982dbd0b5a96d861b58c19de71259cb96030b22 100644 (file)
@@ -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,
@@ -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)
       }
     })