From: Thorsten Lünborg Date: Wed, 13 Apr 2022 10:20:39 +0000 (+0200) Subject: fix(runtime-dom): properly handle style properties with undefined values (#5348) X-Git-Tag: v3.2.33~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85af1398637ee91c6ebabb73bf42250320311e19;p=thirdparty%2Fvuejs%2Fcore.git fix(runtime-dom): properly handle style properties with undefined values (#5348) fix #5322 --- diff --git a/packages/runtime-dom/__tests__/patchStyle.spec.ts b/packages/runtime-dom/__tests__/patchStyle.spec.ts index 92b30aa581..409d6936ea 100644 --- a/packages/runtime-dom/__tests__/patchStyle.spec.ts +++ b/packages/runtime-dom/__tests__/patchStyle.spec.ts @@ -37,7 +37,18 @@ describe(`runtime-dom: style patching`, () => { it('remove if falsy value', () => { const el = document.createElement('div') - patchProp(el, 'style', { color: 'red' }, { color: undefined }) + patchProp(el, 'style', null, { + color: undefined, + borderRadius: null + }) + expect(el.style.cssText.replace(/\s/g, '')).toBe('') + + patchProp( + el, + 'style', + { color: 'red' }, + { color: null, borderRadius: undefined } + ) expect(el.style.cssText.replace(/\s/g, '')).toBe('') }) diff --git a/packages/runtime-dom/src/modules/style.ts b/packages/runtime-dom/src/modules/style.ts index a9cc67ba5e..f4924ea2ec 100644 --- a/packages/runtime-dom/src/modules/style.ts +++ b/packages/runtime-dom/src/modules/style.ts @@ -45,6 +45,7 @@ function setStyle( if (isArray(val)) { val.forEach(v => setStyle(style, name, v)) } else { + if (val == null) val = '' if (name.startsWith('--')) { // custom property definition style.setProperty(name, val)