diff --git a/packages/runtime-core/src/componentProxy.ts b/packages/runtime-core/src/componentProxy.ts index 92525a20..43be1136 100644 --- a/packages/runtime-core/src/componentProxy.ts +++ b/packages/runtime-core/src/componentProxy.ts @@ -74,6 +74,10 @@ const renderProxyHandlers = { if ((i = target._rawData) !== null && i.hasOwnProperty(key)) { target.$data[key] = value return true + } else if ((i = target._hookProps) !== null && i.hasOwnProperty(key)) { + // this enables returning observable objects from hooks() + i[key] = value + return true } else { return Reflect.set(target, key, value, receiver) } diff --git a/packages/runtime-core/src/componentUtils.ts b/packages/runtime-core/src/componentUtils.ts index 783fd6ed..88a42500 100644 --- a/packages/runtime-core/src/componentUtils.ts +++ b/packages/runtime-core/src/componentUtils.ts @@ -105,22 +105,24 @@ export let isRendering = false export function renderInstanceRoot(instance: ComponentInstance): VNode { let vnode + const { + $options: { hooks }, + render, + $proxy, + $props, + $slots, + $attrs, + $parentVNode + } = instance try { setCurrentInstance(instance) - if (instance.hooks) { - instance._hookProps = - instance.hooks.call(instance.$proxy, instance.$props) || null + if (hooks) { + instance._hookProps = hooks.call($proxy, $props) || null } if (__DEV__) { isRendering = true } - vnode = instance.render.call( - instance.$proxy, - instance.$props, - instance.$slots, - instance.$attrs, - instance.$parentVNode - ) + vnode = render.call($proxy, $props, $slots, $attrs, $parentVNode) if (__DEV__) { isRendering = false } @@ -128,7 +130,7 @@ export function renderInstanceRoot(instance: ComponentInstance): VNode { } catch (err) { handleError(err, instance, ErrorTypes.RENDER) } - return normalizeComponentRoot(vnode, instance.$parentVNode) + return normalizeComponentRoot(vnode, $parentVNode) } export function renderFunctionalRoot(vnode: VNode): VNode {