]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: use more descriptive name for v-show original display key
authorEvan You <yyx990803@gmail.com>
Sun, 25 Feb 2024 13:50:47 +0000 (21:50 +0800)
committerEvan You <yyx990803@gmail.com>
Sun, 25 Feb 2024 13:50:47 +0000 (21:50 +0800)
packages/runtime-core/__tests__/hydration.spec.ts
packages/runtime-dom/src/directives/vShow.ts
packages/runtime-dom/src/modules/style.ts

index da00d7635999af047b3eebbbbf76752c25c55b91..6caa2442e18ce615a6de8eb9c9c7d635c4ac6ee7 100644 (file)
@@ -26,7 +26,7 @@ import {
 } from '@vue/runtime-dom'
 import { type SSRContext, renderToString } from '@vue/server-renderer'
 import { PatchFlags } from '@vue/shared'
-import { vShowOldKey } from '../../runtime-dom/src/directives/vShow'
+import { vShowOriginalDisplay } from '../../runtime-dom/src/directives/vShow'
 
 function mountWithHydration(html: string, render: () => any) {
   const container = document.createElement('div')
@@ -1252,7 +1252,7 @@ describe('SSR hydration', () => {
         foo
       </div>
     `)
-    expect((container.firstChild as any)[vShowOldKey]).toBe('')
+    expect((container.firstChild as any)[vShowOriginalDisplay]).toBe('')
     expect(vnode.el).toBe(container.firstChild)
     expect(`mismatch`).not.toHaveBeenWarned()
   })
index 4bf6779edfd069d02b331c59c4e96229eb68588e..5bf48b277d9fce3dea90d1f42a44f1bfce069e88 100644 (file)
@@ -1,15 +1,16 @@
 import type { ObjectDirective } from '@vue/runtime-core'
 
-export const vShowOldKey = Symbol('_vod')
+export const vShowOriginalDisplay = Symbol('_vod')
 
 interface VShowElement extends HTMLElement {
   // _vod = vue original display
-  [vShowOldKey]: string
+  [vShowOriginalDisplay]: string
 }
 
 export const vShow: ObjectDirective<VShowElement> & { name?: 'show' } = {
   beforeMount(el, { value }, { transition }) {
-    el[vShowOldKey] = el.style.display === 'none' ? '' : el.style.display
+    el[vShowOriginalDisplay] =
+      el.style.display === 'none' ? '' : el.style.display
     if (transition && value) {
       transition.beforeEnter(el)
     } else {
@@ -24,7 +25,7 @@ export const vShow: ObjectDirective<VShowElement> & { name?: 'show' } = {
   updated(el, { value, oldValue }, { transition }) {
     if (
       !value === !oldValue &&
-      (el.style.display === el[vShowOldKey] || !value)
+      (el.style.display === el[vShowOriginalDisplay] || !value)
     )
       return
     if (transition) {
@@ -51,7 +52,7 @@ if (__DEV__) {
 }
 
 function setDisplay(el: VShowElement, value: unknown): void {
-  el.style.display = value ? el[vShowOldKey] : 'none'
+  el.style.display = value ? el[vShowOriginalDisplay] : 'none'
 }
 
 // SSR vnode transforms, only used when user includes client-oriented render
index 11f7ce1c027b9da0bcfbaa4f9df770e8b88918fd..1f45966c3c4692e990c18a940417b42fec54f7e3 100644 (file)
@@ -1,6 +1,6 @@
 import { capitalize, hyphenate, isArray, isString } from '@vue/shared'
 import { camelize, warn } from '@vue/runtime-core'
-import { vShowOldKey } from '../directives/vShow'
+import { vShowOriginalDisplay } from '../directives/vShow'
 import { CSS_VAR_TEXT } from '../helpers/useCssVars'
 
 type Style = string | Record<string, string | string[]> | null
@@ -53,8 +53,8 @@ export function patchStyle(el: Element, prev: Style, next: 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) {
-    el[vShowOldKey] = hasControlledDisplay ? style.display : ''
+  if (vShowOriginalDisplay in el) {
+    el[vShowOriginalDisplay] = hasControlledDisplay ? style.display : ''
     style.display = currentDisplay
   }
 }