]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(reactivity): fix markRaw error on already marked object (#11864)
authorKonv Suu <2583695112@qq.com>
Tue, 10 Sep 2024 07:40:43 +0000 (15:40 +0800)
committerGitHub <noreply@github.com>
Tue, 10 Sep 2024 07:40:43 +0000 (15:40 +0800)
close #11862

packages/reactivity/__tests__/reactive.spec.ts
packages/reactivity/src/reactive.ts

index a90ea27f1381dda744284c1d6ab2eb780c3dd879..3b3baa1906c58d42e0fd710531054140935cd1b5 100644 (file)
@@ -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 }),
index cdcc7759b7601eeafbc3d4fb14e255d4bafc2750..7d9c33aa4d059f74e064c185504c36517df98bdf 100644 (file)
@@ -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> = T & { [RawSymbol]?: true }
  * @see {@link https://vuejs.org/api/reactivity-advanced.html#markraw}
  */
 export function markRaw<T extends object>(value: T): Raw<T> {
-  if (Object.isExtensible(value)) {
+  if (!hasOwn(value, ReactiveFlags.SKIP) && Object.isExtensible(value)) {
     def(value, ReactiveFlags.SKIP, true)
   }
   return value