From 5b002869c533220706f9788b496b8ca8d8e98609 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 7 Dec 2023 10:07:25 +0800 Subject: [PATCH] fix(runtime-dom): fix width and height prop check condition close #9762 --- packages/runtime-dom/__tests__/patchProps.spec.ts | 7 +++++++ packages/runtime-dom/src/patchProp.ts | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/runtime-dom/__tests__/patchProps.spec.ts b/packages/runtime-dom/__tests__/patchProps.spec.ts index 19554b02810..f5542c17d8c 100644 --- a/packages/runtime-dom/__tests__/patchProps.spec.ts +++ b/packages/runtime-dom/__tests__/patchProps.spec.ts @@ -300,6 +300,13 @@ describe('runtime-dom: props patching', () => { expect(el.getAttribute('width')).toBe('24px') }) + // # 9762 should fallthrough to `key in el` logic for non embedded tags + test('width and height on custom elements', () => { + const el = document.createElement('foobar') + patchProp(el, 'width', null, '24px') + expect(el.getAttribute('width')).toBe('24px') + }) + test('translate attribute', () => { const el = document.createElement('div') patchProp(el, 'translate', null, 'no') diff --git a/packages/runtime-dom/src/patchProp.ts b/packages/runtime-dom/src/patchProp.ts index 6c839045a96..9aab512eecc 100644 --- a/packages/runtime-dom/src/patchProp.ts +++ b/packages/runtime-dom/src/patchProp.ts @@ -113,12 +113,14 @@ function shouldSetAsProp( // #8780 the width or height of embedded tags must be set as attribute if (key === 'width' || key === 'height') { const tag = el.tagName - return !( + if ( tag === 'IMG' || tag === 'VIDEO' || tag === 'CANVAS' || tag === 'SOURCE' - ) + ) { + return false + } } // native onclick with string value, must be set as attribute