From: Konv Suu <2583695112@qq.com> Date: Tue, 10 Sep 2024 07:40:43 +0000 (+0800) Subject: fix(reactivity): fix markRaw error on already marked object (#11864) X-Git-Tag: v3.5.4~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67d6596d40b1807b9cd8eb0d9282932ea77be3c0;p=thirdparty%2Fvuejs%2Fcore.git fix(reactivity): fix markRaw error on already marked object (#11864) close #11862 --- diff --git a/packages/reactivity/__tests__/reactive.spec.ts b/packages/reactivity/__tests__/reactive.spec.ts index a90ea27f13..3b3baa1906 100644 --- a/packages/reactivity/__tests__/reactive.spec.ts +++ b/packages/reactivity/__tests__/reactive.spec.ts @@ -293,6 +293,13 @@ describe('reactivity/reactive', () => { expect(() => markRaw(obj)).not.toThrowError() }) + test('markRaw should not redefine on an marked object', () => { + const obj = markRaw({ foo: 1 }) + const raw = markRaw(obj) + expect(raw).toBe(obj) + expect(() => markRaw(obj)).not.toThrowError() + }) + test('should not observe non-extensible objects', () => { const obj = reactive({ foo: Object.preventExtensions({ a: 1 }), diff --git a/packages/reactivity/src/reactive.ts b/packages/reactivity/src/reactive.ts index cdcc7759b7..7d9c33aa4d 100644 --- a/packages/reactivity/src/reactive.ts +++ b/packages/reactivity/src/reactive.ts @@ -1,4 +1,4 @@ -import { def, isObject, toRawType } from '@vue/shared' +import { def, hasOwn, isObject, toRawType } from '@vue/shared' import { mutableHandlers, readonlyHandlers, @@ -405,7 +405,7 @@ export type Raw = T & { [RawSymbol]?: true } * @see {@link https://vuejs.org/api/reactivity-advanced.html#markraw} */ export function markRaw(value: T): Raw { - if (Object.isExtensible(value)) { + if (!hasOwn(value, ReactiveFlags.SKIP) && Object.isExtensible(value)) { def(value, ReactiveFlags.SKIP, true) } return value