fix(async-component): forward refs on async component wrapper
fix #2671
This commit is contained in:
@@ -3,11 +3,12 @@ import {
|
||||
ConcreteComponent,
|
||||
currentInstance,
|
||||
ComponentInternalInstance,
|
||||
isInSSRComponentSetup
|
||||
isInSSRComponentSetup,
|
||||
ComponentOptions
|
||||
} from './component'
|
||||
import { isFunction, isObject } from '@vue/shared'
|
||||
import { ComponentPublicInstance } from './componentPublicInstance'
|
||||
import { createVNode } from './vnode'
|
||||
import { createVNode, VNode } from './vnode'
|
||||
import { defineComponent } from './apiDefineComponent'
|
||||
import { warn } from './warning'
|
||||
import { ref } from '@vue/reactivity'
|
||||
@@ -34,6 +35,9 @@ export interface AsyncComponentOptions<T = any> {
|
||||
) => any
|
||||
}
|
||||
|
||||
export const isAsyncWrapper = (i: ComponentInternalInstance | VNode): boolean =>
|
||||
!!(i.type as ComponentOptions).__asyncLoader
|
||||
|
||||
export function defineAsyncComponent<
|
||||
T extends Component = { new (): ComponentPublicInstance }
|
||||
>(source: AsyncComponentLoader<T> | AsyncComponentOptions<T>): T {
|
||||
@@ -193,7 +197,10 @@ export function defineAsyncComponent<
|
||||
|
||||
function createInnerComp(
|
||||
comp: ConcreteComponent,
|
||||
{ vnode: { props, children } }: ComponentInternalInstance
|
||||
{ vnode: { ref, props, children } }: ComponentInternalInstance
|
||||
) {
|
||||
return createVNode(comp, props, children)
|
||||
const vnode = createVNode(comp, props, children)
|
||||
// ensure inner component inherits the async wrapper's ref owner
|
||||
vnode.ref = ref
|
||||
return vnode
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user