import {
+ ref,
render,
useCssVars,
h,
id
)
})
+
+ test('with subTree changed', async () => {
+ const state = reactive({ color: 'red' })
+ const value = ref(true)
+ const root = document.createElement('div')
+
+ const App = {
+ setup() {
+ useCssVars(() => state)
+ return () => (value.value ? [h('div')] : [h('div'), h('div')])
+ }
+ }
+
+ render(h(App), root)
+ // css vars use with fallback tree
+ for (const c of [].slice.call(root.children as any)) {
+ expect((c as HTMLElement).style.getPropertyValue(`--color`)).toBe(`red`)
+ }
+
+ value.value = false
+ await nextTick()
+ for (const c of [].slice.call(root.children as any)) {
+ expect((c as HTMLElement).style.getPropertyValue(`--color`)).toBe('red')
+ }
+ })
})
ComponentPublicInstance,
getCurrentInstance,
onMounted,
- watchEffect,
warn,
VNode,
Fragment,
- unref
+ unref,
+ onUpdated,
+ watchEffect
} from '@vue/runtime-core'
import { ShapeFlags } from '@vue/shared'
? `${instance.type.__scopeId.replace(/^data-v-/, '')}-`
: ``
- onMounted(() => {
- watchEffect(() => {
- setVarsOnVNode(instance.subTree, getter(instance.proxy!), prefix)
- })
- })
+ const setVars = () =>
+ setVarsOnVNode(instance.subTree, getter(instance.proxy!), prefix)
+ onMounted(() => watchEffect(setVars))
+ onUpdated(setVars)
}
function setVarsOnVNode(