genFlagText([PatchFlags.PROPS, PatchFlags.HYDRATE_EVENTS])
)
})
+
+ // #5870
+ test('HYDRATE_EVENTS on dynamic component', () => {
+ const { node } = parseWithElementTransform(
+ `<component :is="foo" @input="foo" />`,
+ {
+ directiveTransforms: {
+ on: transformOn
+ }
+ }
+ )
+ expect(node.patchFlag).toBe(
+ genFlagText([PatchFlags.PROPS, PatchFlags.HYDRATE_EVENTS])
+ )
+ })
})
describe('dynamic component', () => {
// props
if (props.length > 0) {
- const propsBuildResult = buildProps(node, context)
+ const propsBuildResult = buildProps(
+ node,
+ context,
+ undefined,
+ isComponent,
+ isDynamicComponent
+ )
vnodeProps = propsBuildResult.props
patchFlag = propsBuildResult.patchFlag
dynamicPropNames = propsBuildResult.dynamicPropNames
node: ElementNode,
context: TransformContext,
props: ElementNode['props'] = node.props,
+ isComponent: boolean,
+ isDynamicComponent: boolean,
ssr = false
): {
props: PropsExpression | undefined
shouldUseBlock: boolean
} {
const { tag, loc: elementLoc, children } = node
- const isComponent = node.tagType === ElementTypes.COMPONENT
let properties: ObjectExpression['properties'] = []
const mergeArgs: PropsExpression[] = []
const runtimeDirectives: DirectiveNode[] = []
const name = key.content
const isEventHandler = isOn(name)
if (
- !isComponent &&
isEventHandler &&
+ (!isComponent || isDynamicComponent) &&
// omit the flag for click handlers because hydration gives click
// dedicated fast path.
name.toLowerCase() !== 'onclick' &&
}
if (nonNameProps.length > 0) {
- const { props, directives } = buildProps(node, context, nonNameProps)
+ const { props, directives } = buildProps(
+ node,
+ context,
+ nonNameProps,
+ false,
+ false
+ )
slotProps = props
if (directives.length) {
TRANSITION_GROUP,
CREATE_VNODE,
CallExpression,
- JSChildNode
+ JSChildNode,
+ RESOLVE_DYNAMIC_COMPONENT
} from '@vue/compiler-dom'
import { SSR_RENDER_COMPONENT, SSR_RENDER_VNODE } from '../runtimeHelpers'
import {
}
const component = resolveComponentType(node, context, true /* ssr */)
+ const isDynamicComponent =
+ isObject(component) && component.callee === RESOLVE_DYNAMIC_COMPONENT
componentTypeMap.set(node, component)
if (isSymbol(component)) {
if (node.props.length) {
// note we are not passing ssr: true here because for components, v-on
// handlers should still be passed
- const { props, directives } = buildProps(node, context)
+ const { props, directives } = buildProps(
+ node,
+ context,
+ undefined,
+ true,
+ isDynamicComponent
+ )
if (props || directives.length) {
propsExp = buildSSRProps(props, directives, context)
}
node,
context,
node.props,
+ false /* isComponent */,
+ false /* isDynamicComponent */,
true /* ssr */
)
if (props || directives.length) {