Skip to content

Commit

Permalink
fix(runtime-core): skip functional components in public $parent chain…
Browse files Browse the repository at this point in the history
… traversal

fix #2437
  • Loading branch information
yyx990803 committed Nov 27, 2020
1 parent 7cd85be commit 53f4885
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/runtime-core/src/componentPublicInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ export type ComponentPublicInstance<

type PublicPropertiesMap = Record<string, (i: ComponentInternalInstance) => any>

/**
* #2437 In Vue 3, functional components do not have a public instance proxy but
* they exist in the internal parent chain. For code that relies on traversing
* public $parent chains, skip functional ones and go to the parent instead.
*/
const getPublicInstance = (
i: ComponentInternalInstance | null
): ComponentPublicInstance | null =>
i && (i.proxy ? i.proxy : getPublicInstance(i.parent))

const publicPropertiesMap: PublicPropertiesMap = extend(Object.create(null), {
$: i => i,
$el: i => i.vnode.el,
Expand All @@ -208,7 +218,7 @@ const publicPropertiesMap: PublicPropertiesMap = extend(Object.create(null), {
$attrs: i => (__DEV__ ? shallowReadonly(i.attrs) : i.attrs),
$slots: i => (__DEV__ ? shallowReadonly(i.slots) : i.slots),
$refs: i => (__DEV__ ? shallowReadonly(i.refs) : i.refs),
$parent: i => i.parent && i.parent.proxy,
$parent: i => getPublicInstance(i.parent),
$root: i => i.root && i.root.proxy,
$emit: i => i.emit,
$options: i => (__FEATURE_OPTIONS_API__ ? resolveMergedOptions(i) : i.type),
Expand Down

0 comments on commit 53f4885

Please sign in to comment.