mirror of https://github.com/vuejs/core.git
fix(reactivity): fix markRaw error on already marked object (#11864)
close #11862
This commit is contained in:
parent
d13cd22eef
commit
67d6596d40
|
@ -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 }),
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue