File tree 2 files changed +33
-7
lines changed
2 files changed +33
-7
lines changed Original file line number Diff line number Diff line change 1
1
import {
2
+ ref ,
2
3
render ,
3
4
useCssVars ,
4
5
h ,
@@ -125,4 +126,29 @@ describe('useCssVars', () => {
125
126
id
126
127
)
127
128
} )
129
+
130
+ test ( 'with subTree changed' , async ( ) => {
131
+ const state = reactive ( { color : 'red' } )
132
+ const value = ref ( true )
133
+ const root = document . createElement ( 'div' )
134
+
135
+ const App = {
136
+ setup ( ) {
137
+ useCssVars ( ( ) => state )
138
+ return ( ) => ( value . value ? [ h ( 'div' ) ] : [ h ( 'div' ) , h ( 'div' ) ] )
139
+ }
140
+ }
141
+
142
+ render ( h ( App ) , root )
143
+ // css vars use with fallback tree
144
+ for ( const c of [ ] . slice . call ( root . children as any ) ) {
145
+ expect ( ( c as HTMLElement ) . style . getPropertyValue ( `--color` ) ) . toBe ( `red` )
146
+ }
147
+
148
+ value . value = false
149
+ await nextTick ( )
150
+ for ( const c of [ ] . slice . call ( root . children as any ) ) {
151
+ expect ( ( c as HTMLElement ) . style . getPropertyValue ( `--color` ) ) . toBe ( 'red' )
152
+ }
153
+ } )
128
154
} )
Original file line number Diff line number Diff line change @@ -2,11 +2,12 @@ import {
2
2
ComponentPublicInstance ,
3
3
getCurrentInstance ,
4
4
onMounted ,
5
- watchEffect ,
6
5
warn ,
7
6
VNode ,
8
7
Fragment ,
9
- unref
8
+ unref ,
9
+ onUpdated ,
10
+ watchEffect
10
11
} from '@vue/runtime-core'
11
12
import { ShapeFlags } from '@vue/shared'
12
13
@@ -27,11 +28,10 @@ export function useCssVars(
27
28
? `${ instance . type . __scopeId . replace ( / ^ d a t a - v - / , '' ) } -`
28
29
: ``
29
30
30
- onMounted ( ( ) => {
31
- watchEffect ( ( ) => {
32
- setVarsOnVNode ( instance . subTree , getter ( instance . proxy ! ) , prefix )
33
- } )
34
- } )
31
+ const setVars = ( ) =>
32
+ setVarsOnVNode ( instance . subTree , getter ( instance . proxy ! ) , prefix )
33
+ onMounted ( ( ) => watchEffect ( setVars ) )
34
+ onUpdated ( setVars )
35
35
}
36
36
37
37
function setVarsOnVNode (
You can’t perform that action at this time.
0 commit comments