fix(reactivity): check skip first before checking ref when creating observer (#12813)

fix #12812
This commit is contained in:
Xiersa 2022-10-11 13:26:20 +08:00 committed by GitHub
parent 4a0d88e46e
commit 5d26f815c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,6 @@ import {
hasOwn,
isArray,
hasProto,
isObject,
isPlainObject,
isPrimitive,
isUndef,
@ -108,23 +107,21 @@ export function observe(
shallow?: boolean,
ssrMockReactivity?: boolean
): Observer | void {
if (!isObject(value) || isRef(value) || value instanceof VNode) {
return
if (value && hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
return value.__ob__
}
let ob: Observer | void
if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
ob = value.__ob__
} else if (
if (
shouldObserve &&
(ssrMockReactivity || !isServerRendering()) &&
(isArray(value) || isPlainObject(value)) &&
Object.isExtensible(value) &&
!value.__v_skip /* ReactiveFlags.SKIP */ &&
!rawMap.has(value)
!rawMap.has(value) &&
!isRef(value) &&
!(value instanceof VNode)
) {
ob = new Observer(value, shallow, ssrMockReactivity)
return new Observer(value, shallow, ssrMockReactivity)
}
return ob
}
/**