Skip to content

Commit

Permalink
fix(runtime-core): render context set should not unwrap reactive values
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 27, 2020
1 parent 012bc5d commit 27fbfbd
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/runtime-core/src/componentProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ComputedOptions,
MethodOptions
} from './apiOptions'
import { UnwrapRef, ReactiveEffect, isRef, toRaw } from '@vue/reactivity'
import { UnwrapRef, ReactiveEffect, isRef, isReactive } from '@vue/reactivity'
import { warn } from './warning'
import { Slots } from './componentSlots'
import {
Expand Down Expand Up @@ -169,12 +169,18 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
if (data !== EMPTY_OBJ && hasOwn(data, key)) {
data[key] = value
} else if (hasOwn(renderContext, key)) {
const oldValue = renderContext[key]
value = toRaw(value)
if (isRef(oldValue) && !isRef(value)) {
oldValue.value = value
} else {
// context is already reactive (user returned reactive object from setup())
// just set directly
if (isReactive(renderContext)) {
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) {
__DEV__ &&
Expand Down

0 comments on commit 27fbfbd

Please sign in to comment.