From 1ca94f0b97dfe6c6e23a327dc2c16c01d7e5d7eb Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Mon, 30 Jan 2023 06:56:38 +0000 Subject: [PATCH 1/2] fix: correctly update styles --- src/platforms/web/runtime/modules/style.ts | 2 +- test/unit/modules/vdom/modules/style.spec.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/platforms/web/runtime/modules/style.ts b/src/platforms/web/runtime/modules/style.ts index ff6e14da495..43bde16ef3e 100644 --- a/src/platforms/web/runtime/modules/style.ts +++ b/src/platforms/web/runtime/modules/style.ts @@ -91,7 +91,7 @@ function updateStyle(oldVnode: VNodeWithData, vnode: VNodeWithData) { } for (name in newStyle) { cur = newStyle[name] - if (cur !== oldStyle[name]) { + if (cur !== oldStyle[name] || !el.style[name]) { // ie9 setting to null has no effect, must use empty string setProp(el, name, cur == null ? '' : cur) } diff --git a/test/unit/modules/vdom/modules/style.spec.ts b/test/unit/modules/vdom/modules/style.spec.ts index ec57ae88d6e..3e355efa1f8 100644 --- a/test/unit/modules/vdom/modules/style.spec.ts +++ b/test/unit/modules/vdom/modules/style.spec.ts @@ -28,6 +28,14 @@ describe('vdom style module', () => { expect(elm.style.display).toBe('block') }) + it('border related style should update correctly', () => { + const vnode1 = new VNode('p', { style: { border: 'border: 10px solid red', 'border-bottom': '10px solid blue' } }) + const vnode2 = new VNode('p', { style: { 'border-right': '10px solid red', 'border-bottom': '10px solid blue' } }) + patch(null, vnode1) + const elm = patch(vnode1, vnode2) + expect(elm.style.borderBottom).toBe('10px solid blue') + }) + it('should remove elements attrs', () => { const vnode1 = new VNode('p', { style: { fontSize: '12px' } }) const vnode2 = new VNode('p', { style: { display: 'block' } }) From fec64dc3b6caedb85bae7c2750dfb4c3c07df16c Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Mon, 30 Jan 2023 15:28:58 +0800 Subject: [PATCH 2/2] chore: update test --- test/unit/modules/vdom/modules/style.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/modules/vdom/modules/style.spec.ts b/test/unit/modules/vdom/modules/style.spec.ts index 3e355efa1f8..9f694a94019 100644 --- a/test/unit/modules/vdom/modules/style.spec.ts +++ b/test/unit/modules/vdom/modules/style.spec.ts @@ -29,7 +29,7 @@ describe('vdom style module', () => { }) it('border related style should update correctly', () => { - const vnode1 = new VNode('p', { style: { border: 'border: 10px solid red', 'border-bottom': '10px solid blue' } }) + const vnode1 = new VNode('p', { style: { border: '10px solid red', 'border-bottom': '10px solid blue' } }) const vnode2 = new VNode('p', { style: { 'border-right': '10px solid red', 'border-bottom': '10px solid blue' } }) patch(null, vnode1) const elm = patch(vnode1, vnode2)