From ea98cfeccded9e1ec1402254b6f2aeec2e7fc3cb Mon Sep 17 00:00:00 2001 From: Madsen Date: Sat, 5 Feb 2022 22:06:17 +0800 Subject: [PATCH] fix(runtime-dom): fix an update error when the style changed from string to object --- packages/runtime-dom/src/modules/style.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/runtime-dom/src/modules/style.ts b/packages/runtime-dom/src/modules/style.ts index a9cc67ba5e2..22a52ba83f7 100644 --- a/packages/runtime-dom/src/modules/style.ts +++ b/packages/runtime-dom/src/modules/style.ts @@ -7,16 +7,20 @@ export function patchStyle(el: Element, prev: Style, next: Style) { const style = (el as HTMLElement).style const isCssString = isString(next) if (next && !isCssString) { - for (const key in next) { - setStyle(style, key, next[key]) - } - if (prev && !isString(prev)) { - for (const key in prev) { - if (next[key] == null) { - setStyle(style, key, '') + if (prev) { + if (isString(prev)) { + style.cssText = '' + } else { + for (const key in prev) { + if (next[key] == null) { + setStyle(style, key, ''); + } } } } + for (const key in next) { + setStyle(style, key, next[key]) + } } else { const currentDisplay = style.display if (isCssString) {