fix(runtime-core): render context set should not unwrap reactive values

This commit is contained in:
Evan You 2020-01-27 18:05:30 -05:00
parent 012bc5df9d
commit 27fbfbdb8b

View File

@ -8,7 +8,7 @@ import {
ComputedOptions, ComputedOptions,
MethodOptions MethodOptions
} from './apiOptions' } from './apiOptions'
import { UnwrapRef, ReactiveEffect, isRef, toRaw } from '@vue/reactivity' import { UnwrapRef, ReactiveEffect, isRef, isReactive } from '@vue/reactivity'
import { warn } from './warning' import { warn } from './warning'
import { Slots } from './componentSlots' import { Slots } from './componentSlots'
import { import {
@ -169,12 +169,18 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
if (data !== EMPTY_OBJ && hasOwn(data, key)) { if (data !== EMPTY_OBJ && hasOwn(data, key)) {
data[key] = value data[key] = value
} else if (hasOwn(renderContext, key)) { } else if (hasOwn(renderContext, key)) {
const oldValue = renderContext[key] // context is already reactive (user returned reactive object from setup())
value = toRaw(value) // just set directly
if (isRef(oldValue) && !isRef(value)) { if (isReactive(renderContext)) {
oldValue.value = value
} else {
renderContext[key] = value renderContext[key] = value
} else {
// handle potential ref set
const oldValue = renderContext[key]
if (isRef(oldValue) && !isRef(value)) {
oldValue.value = value
} else {
renderContext[key] = value
}
} }
} else if (key[0] === '$' && key.slice(1) in target) { } else if (key[0] === '$' && key.slice(1) in target) {
__DEV__ && __DEV__ &&