diff --git a/packages/reactivity/__tests__/reactiveArray.spec.ts b/packages/reactivity/__tests__/reactiveArray.spec.ts index 1c6fcefd592..d405608f8c4 100644 --- a/packages/reactivity/__tests__/reactiveArray.spec.ts +++ b/packages/reactivity/__tests__/reactiveArray.spec.ts @@ -99,6 +99,21 @@ describe('reactivity/reactive/Array', () => { expect(fn).toHaveBeenCalledTimes(1) }) + test("should reactive when mutate array's index", () => { + const original = [1, 2, 3] + const observed = reactive(original) + + let dummy + effect(() => { + dummy = observed.hasOwnProperty(0) + }) + + expect(dummy).toBe(true) + + delete observed[0] + expect(dummy).toBe(false) + }) + test('shift on Array should trigger dependency once', () => { const arr = reactive([1, 2, 3]) const fn = vi.fn() diff --git a/packages/reactivity/src/baseHandlers.ts b/packages/reactivity/src/baseHandlers.ts index 7cee7aa9bd5..36707aa9138 100644 --- a/packages/reactivity/src/baseHandlers.ts +++ b/packages/reactivity/src/baseHandlers.ts @@ -80,10 +80,12 @@ function createArrayInstrumentations() { return instrumentations } -function hasOwnProperty(this: object, key: string) { +function hasOwnProperty(this: object, key: unknown) { + // #10455 hasOwnProperty may be called with non-string values + key = '' + key const obj = toRaw(this) track(obj, TrackOpTypes.HAS, key) - return obj.hasOwnProperty(key) + return obj.hasOwnProperty(key as string) } class BaseReactiveHandler implements ProxyHandler {