diff --git a/packages/runtime-core/__tests__/rendererAttrsFallthrough.spec.ts b/packages/runtime-core/__tests__/rendererAttrsFallthrough.spec.ts index fe34eee6010..62cf3b4d6aa 100644 --- a/packages/runtime-core/__tests__/rendererAttrsFallthrough.spec.ts +++ b/packages/runtime-core/__tests__/rendererAttrsFallthrough.spec.ts @@ -227,6 +227,27 @@ describe('attribute fallthrough', () => { expect(node.hasAttribute('foo')).toBe(false) }) + it('should fallthrough with inheritAttrs: true and no declared props', () => { + const Parent = { + render() { + return h(Child, { class: 'parent' }) + } + } + + const Child = defineComponent({ + inheritAttrs: true, + render() { + return h('div') + } + }) + + const root = document.createElement('div') + document.body.appendChild(root) + render(h(Parent), root) + + expect(root.innerHTML).toMatch(`
`) + }) + it('should not fallthrough with inheritAttrs: false', () => { const Parent = { render() { diff --git a/packages/runtime-core/src/componentRenderUtils.ts b/packages/runtime-core/src/componentRenderUtils.ts index 6b3be672792..4f1f7bd9dd1 100644 --- a/packages/runtime-core/src/componentRenderUtils.ts +++ b/packages/runtime-core/src/componentRenderUtils.ts @@ -80,8 +80,8 @@ export function renderComponentRoot( // attr merging if ( - Component.props != null && - Component.inheritAttrs !== false && + (Component.inheritAttrs || + (Component.props != null && Component.inheritAttrs !== false)) && attrs !== EMPTY_OBJ && Object.keys(attrs).length ) {