diff --git a/packages/core/src/component.ts b/packages/core/src/component.ts index 1790aa33..bb981012 100644 --- a/packages/core/src/component.ts +++ b/packages/core/src/component.ts @@ -21,6 +21,7 @@ export interface ComponentClass extends Flatten { export interface FunctionalComponent

extends RenderFunction

{ pure?: boolean props?: ComponentPropsOptions

+ inheritAttrs?: boolean } // this interface is merged with the class type diff --git a/packages/core/src/componentOptions.ts b/packages/core/src/componentOptions.ts index d459a82e..c8ce0caa 100644 --- a/packages/core/src/componentOptions.ts +++ b/packages/core/src/componentOptions.ts @@ -13,6 +13,7 @@ export interface ComponentOptions { computed?: ComponentComputedOptions watch?: ComponentWatchOptions render?: RenderFunction

+ inheritAttrs?: boolean // TODO other options readonly [key: string]: any } diff --git a/packages/core/src/componentUtils.ts b/packages/core/src/componentUtils.ts index ff893b66..d4c4dc7e 100644 --- a/packages/core/src/componentUtils.ts +++ b/packages/core/src/componentUtils.ts @@ -71,7 +71,11 @@ export function renderInstanceRoot(instance: MountedComponent) { } } } - return normalizeComponentRoot(vnode, instance.$parentVNode) + return normalizeComponentRoot( + vnode, + instance.$parentVNode, + instance.$options.inheritAttrs + ) } export function teardownComponentInstance(instance: MountedComponent) { @@ -88,7 +92,8 @@ export function teardownComponentInstance(instance: MountedComponent) { export function normalizeComponentRoot( vnode: any, - componentVNode: VNode | null + componentVNode: VNode | null, + inheritAttrs: boolean | void ): VNode { if (vnode == null) { vnode = createTextVNode('') @@ -104,7 +109,7 @@ export function normalizeComponentRoot( (flags & VNodeFlags.COMPONENT || flags & VNodeFlags.ELEMENT) ) { const parentData = componentVNode.data - if (parentData != null) { + if (parentData != null && inheritAttrs !== false) { let extraData: any = null for (const key in parentData) { // attrs/class/style bindings on parentVNode are merged down to child diff --git a/packages/core/src/createRenderer.ts b/packages/core/src/createRenderer.ts index 4c8ebb4f..1deb1630 100644 --- a/packages/core/src/createRenderer.ts +++ b/packages/core/src/createRenderer.ts @@ -278,7 +278,8 @@ export function createRenderer(options: RendererOptions) { // functional component const subTree = (vnode.children = normalizeComponentRoot( (tag as FunctionalComponent)(data || EMPTY_OBJ, slots || EMPTY_OBJ), - vnode + vnode, + (tag as FunctionalComponent).inheritAttrs )) el = vnode.el = mount(subTree, null, parentComponent, isSVG, null) } @@ -562,7 +563,8 @@ export function createRenderer(options: RendererOptions) { if (shouldUpdate) { const nextTree = (nextVNode.children = normalizeComponentRoot( render(nextProps || EMPTY_OBJ, nextSlots || EMPTY_OBJ), - nextVNode + nextVNode, + render.inheritAttrs )) patch(prevTree, nextTree, container, parentComponent, isSVG) nextVNode.el = nextTree.el