fix(runtime-core): skip functional components in public $parent chain traversal
fix #2437
This commit is contained in:
parent
7cd85be2db
commit
53f4885d9e
@ -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,
|
||||
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user