]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-dom): properly handle style properties with undefined values (#5348)
authorThorsten Lünborg <t.luenborg@googlemail.com>
Wed, 13 Apr 2022 10:20:39 +0000 (12:20 +0200)
committerGitHub <noreply@github.com>
Wed, 13 Apr 2022 10:20:39 +0000 (06:20 -0400)
fix #5322

packages/runtime-dom/__tests__/patchStyle.spec.ts
packages/runtime-dom/src/modules/style.ts

index 92b30aa5815bf8fb7451b41ea2ee64721b2ec455..409d6936eaf8fd5dc8481270e91b466baf581616 100644 (file)
@@ -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('')
   })
 
index a9cc67ba5e2520d86f3a668ebe3ce5e0869963a6..f4924ea2ec6fb559ee8bb140377229e3b70f3ba5 100644 (file)
@@ -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)