Skip to content

Commit 364f890

Browse files
committedFeb 26, 2024·
fix(runtime-dom): fix nested v-show priority regression
close #10338
1 parent 6c74fb0 commit 364f890

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed
 

‎packages/runtime-dom/src/directives/vShow.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import type { ObjectDirective } from '@vue/runtime-core'
22

33
export const vShowOriginalDisplay = Symbol('_vod')
4+
export const vShowHidden = Symbol('_vsh')
45

5-
interface VShowElement extends HTMLElement {
6+
export interface VShowElement extends HTMLElement {
67
// _vod = vue original display
78
[vShowOriginalDisplay]: string
9+
[vShowHidden]: boolean
810
}
911

1012
export const vShow: ObjectDirective<VShowElement> & { name?: 'show' } = {
@@ -23,11 +25,7 @@ export const vShow: ObjectDirective<VShowElement> & { name?: 'show' } = {
2325
}
2426
},
2527
updated(el, { value, oldValue }, { transition }) {
26-
if (
27-
!value === !oldValue &&
28-
(el.style.display === el[vShowOriginalDisplay] || !value)
29-
)
30-
return
28+
if (!value === !oldValue) return
3129
if (transition) {
3230
if (value) {
3331
transition.beforeEnter(el)
@@ -53,6 +51,7 @@ if (__DEV__) {
5351

5452
function setDisplay(el: VShowElement, value: unknown): void {
5553
el.style.display = value ? el[vShowOriginalDisplay] : 'none'
54+
el[vShowHidden] = !value
5655
}
5756

5857
// SSR vnode transforms, only used when user includes client-oriented render

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { capitalize, hyphenate, isArray, isString } from '@vue/shared'
22
import { camelize, warn } from '@vue/runtime-core'
3-
import { vShowOriginalDisplay } from '../directives/vShow'
3+
import {
4+
type VShowElement,
5+
vShowHidden,
6+
vShowOriginalDisplay,
7+
} from '../directives/vShow'
48
import { CSS_VAR_TEXT } from '../helpers/useCssVars'
59

610
type Style = string | Record<string, string | string[]> | null
@@ -10,7 +14,6 @@ const displayRE = /(^|;)\s*display\s*:/
1014
export function patchStyle(el: Element, prev: Style, next: Style) {
1115
const style = (el as HTMLElement).style
1216
const isCssString = isString(next)
13-
const currentDisplay = style.display
1417
let hasControlledDisplay = false
1518
if (next && !isCssString) {
1619
if (prev) {
@@ -50,12 +53,14 @@ export function patchStyle(el: Element, prev: Style, next: Style) {
5053
el.removeAttribute('style')
5154
}
5255
}
53-
// indicates that the `display` of the element is controlled by `v-show`,
54-
// so we always keep the current `display` value regardless of the `style`
55-
// value, thus handing over control to `v-show`.
56+
// indicates the element also has `v-show`.
5657
if (vShowOriginalDisplay in el) {
58+
// make v-show respect the current v-bind style display when shown
5759
el[vShowOriginalDisplay] = hasControlledDisplay ? style.display : ''
58-
style.display = currentDisplay
60+
// if v-show is in hidden state, v-show has higher priority
61+
if ((el as VShowElement)[vShowHidden]) {
62+
style.display = 'none'
63+
}
5964
}
6065
}
6166

0 commit comments

Comments
 (0)
Please sign in to comment.