]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-dom): unify behavior for v-show + style display binding (#10075)
authorcyx <30902641+Duncanxyz@users.noreply.github.com>
Thu, 11 Jan 2024 09:11:35 +0000 (17:11 +0800)
committerGitHub <noreply@github.com>
Thu, 11 Jan 2024 09:11:35 +0000 (17:11 +0800)
close #10074

packages/runtime-dom/src/modules/style.ts

index ce112ab87ed57c7ad26a5e40a0f1a5925bf9d8ef..6341c8a120e0690270e8c64dc698f4c6d094105e 100644 (file)
@@ -7,6 +7,7 @@ type Style = string | Record<string, string | string[]> | null
 
 export function patchStyle(el: Element, prev: Style, next: Style) {
   const style = (el as HTMLElement).style
+  const currentDisplay = style.display
   const isCssString = isString(next)
   if (next && !isCssString) {
     if (prev && !isString(prev)) {
@@ -20,7 +21,6 @@ export function patchStyle(el: Element, prev: Style, next: Style) {
       setStyle(style, key, next[key])
     }
   } else {
-    const currentDisplay = style.display
     if (isCssString) {
       if (prev !== next) {
         // #9821
@@ -33,12 +33,12 @@ export function patchStyle(el: Element, prev: Style, next: Style) {
     } else if (prev) {
       el.removeAttribute('style')
     }
-    // indicates that the `display` of the element is controlled by `v-show`,
-    // so we always keep the current `display` value regardless of the `style`
-    // value, thus handing over control to `v-show`.
-    if (vShowOldKey in el) {
-      style.display = currentDisplay
-    }
+  }
+  // indicates that the `display` of the element is controlled by `v-show`,
+  // so we always keep the current `display` value regardless of the `style`
+  // value, thus handing over control to `v-show`.
+  if (vShowOldKey in el) {
+    style.display = currentDisplay
   }
 }