options: ComponentOptions,
asMixin: boolean = false
) {
- const renderContext =
- instance.renderContext === EMPTY_OBJ
- ? (instance.renderContext = __SSR__ ? {} : reactive({}))
- : instance.renderContext
const ctx = instance.proxy!
const {
// composition
errorCaptured
} = options
+ const renderContext =
+ instance.renderContext === EMPTY_OBJ
+ ? (instance.renderContext = {})
+ : instance.renderContext
+
const globalMixins = instance.appContext.mixins
// call it only during dev
const checkDuplicateProperties = __DEV__ ? createDuplicateChecker() : null
checkDuplicateProperties!(OptionTypes.DATA, key)
}
}
- instance.data = __SSR__ ? data : reactive(data)
+ instance.data = reactive(data)
} else {
// existing data: this is a mixin or extends.
extend(instance.data, data)
}
}
+
if (computedOptions) {
for (const key in computedOptions) {
const opt = (computedOptions as ComputedOptions)[key]
}
}
}
+
if (watchOptions) {
for (const key in watchOptions) {
createWatcher(watchOptions[key], renderContext, ctx, key)
}
}
+
if (provideOptions) {
const provides = isFunction(provideOptions)
? provideOptions.call(ctx)
provide(key, provides[key])
}
}
+
if (injectOptions) {
if (isArray(injectOptions)) {
for (let i = 0; i < injectOptions.length; i++) {
import { VNode, VNodeChild, isVNode } from './vnode'
-import { ReactiveEffect, reactive, shallowReadonly } from '@vue/reactivity'
+import { ReactiveEffect, shallowReadonly } from '@vue/reactivity'
import {
PublicInstanceProxyHandlers,
ComponentPublicInstance,
}
// setup returned bindings.
// assuming a render function compiled from template is present.
- instance.renderContext = __SSR__ ? setupResult : reactive(setupResult)
+ instance.renderContext = setupResult
} else if (__DEV__ && setupResult !== undefined) {
warn(
`setup() should return an object. Received: ${
}
if (instance.renderContext === EMPTY_OBJ) {
- instance.renderContext = __SSR__ ? {} : reactive({})
+ instance.renderContext = {}
}
}
ComputedOptions,
MethodOptions
} from './apiOptions'
-import { UnwrapRef, ReactiveEffect } from '@vue/reactivity'
+import { UnwrapRef, ReactiveEffect, isRef, toRaw } from '@vue/reactivity'
import { warn } from './warning'
import { Slots } from './componentSlots'
import {
OTHER
}
+const unwrapRef = (val: unknown) => (isRef(val) ? val.value : val)
+
export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
get(target: ComponentInternalInstance, key: string) {
// fast path for unscopables when using `with` block
case AccessTypes.DATA:
return data[key]
case AccessTypes.CONTEXT:
- return renderContext[key]
+ return unwrapRef(renderContext[key])
case AccessTypes.PROPS:
return propsProxy![key]
// default: just fallthrough
return data[key]
} else if (hasOwn(renderContext, key)) {
accessCache![key] = AccessTypes.CONTEXT
- return renderContext[key]
+ return unwrapRef(renderContext[key])
} else if (type.props != null) {
// only cache other properties when instance has declared (this stable)
// props
if (data !== EMPTY_OBJ && hasOwn(data, key)) {
data[key] = value
} else if (hasOwn(renderContext, key)) {
- renderContext[key] = value
+ const oldValue = renderContext[key]
+ value = toRaw(value)
+ if (isRef(oldValue) && !isRef(value)) {
+ oldValue.value = value
+ } else {
+ renderContext[key] = value
+ }
} else if (key[0] === '$' && key.slice(1) in target) {
__DEV__ &&
warn(