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 }),
-import { def, isObject, toRawType } from '@vue/shared'
+import { def, hasOwn, isObject, toRawType } from '@vue/shared'
import {
mutableHandlers,
readonlyHandlers,
* @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