@@ -7,8 +7,6 @@ interface VShowElement extends HTMLElement {
7
7
[ vShowOldKey ] : string
8
8
}
9
9
10
- const resolvedPromise = Promise . resolve ( )
11
-
12
10
export const vShow : ObjectDirective < VShowElement > & { name ?: 'show' } = {
13
11
beforeMount ( el , { value } , { transition } ) {
14
12
el [ vShowOldKey ] = el . style . display === 'none' ? '' : el . style . display
@@ -23,17 +21,19 @@ export const vShow: ObjectDirective<VShowElement> & { name?: 'show' } = {
23
21
transition . enter ( el )
24
22
}
25
23
} ,
26
- updated ( el , { value, oldValue } , { transition } ) {
24
+ updated ( el , { value, oldValue } , { transition } , _ , postFlush ) {
27
25
if (
28
26
! value === ! oldValue &&
29
27
( el . style . display === el [ vShowOldKey ] || ( ! value && transition ) )
30
28
)
31
29
return
32
30
if ( transition ) {
33
31
if ( value ) {
34
- transition . beforeEnter ( el )
35
- setDisplay ( el , true )
36
- transition . enter ( el )
32
+ postFlush ! ( ( ) => {
33
+ transition . beforeEnter ( el )
34
+ setDisplay ( el , true )
35
+ transition . enter ( el )
36
+ } )
37
37
} else {
38
38
transition . leave ( el , ( ) => {
39
39
setDisplay ( el , false )
@@ -43,7 +43,9 @@ export const vShow: ObjectDirective<VShowElement> & { name?: 'show' } = {
43
43
// #10038
44
44
// when multi vShow be applied to the same element
45
45
// and the sync setDisplay will impact other vShow
46
- postSetDisplay ( el , value )
46
+ postFlush ! ( ( ) => {
47
+ setDisplay ( el , value )
48
+ } )
47
49
}
48
50
} ,
49
51
beforeUnmount ( el , { value } ) {
@@ -59,12 +61,6 @@ function setDisplay(el: VShowElement, value: unknown): void {
59
61
el . style . display = value ? el [ vShowOldKey ] : 'none'
60
62
}
61
63
62
- function postSetDisplay ( el : VShowElement , value : unknown ) : void {
63
- resolvedPromise . then ( ( ) => {
64
- setDisplay ( el , value )
65
- } )
66
- }
67
-
68
64
// SSR vnode transforms, only used when user includes client-oriented render
69
65
// function in SSR
70
66
export function initVShowForSSR ( ) {
0 commit comments