From 5dae6be1cc76795cae39ece9c8ed6dd9ea00d622 Mon Sep 17 00:00:00 2001 From: hareku Date: Sat, 22 Feb 2020 02:23:42 +0900 Subject: [PATCH] fix(runtime-core): should work fallthrough with inheritAttrs: true --- .../rendererAttrsFallthrough.spec.ts | 21 +++++++++++++++++++ .../runtime-core/src/componentRenderUtils.ts | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) 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 ) {