reactive,
nextTick,
ComponentOptions,
- Suspense
+ Suspense,
+ FunctionalComponent
} from '@vue/runtime-dom'
describe('useCssVars', () => {
}
})
+ // #3894
+ test('with subTree change inside HOC', async () => {
+ const state = reactive({ color: 'red' })
+ const value = ref(true)
+ const root = document.createElement('div')
+
+ const Child: FunctionalComponent = (_, { slots }) => slots.default!()
+
+ const App = {
+ setup() {
+ useCssVars(() => state)
+ return () =>
+ h(
+ Child,
+ null,
+ () => (value.value ? [h('div')] : [h('div'), h('div')])
+ )
+ }
+ }
+
+ render(h(App), root)
+ await nextTick()
+ // 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')
+ }
+ })
+
test('with createStaticVNode', async () => {
const state = reactive({ color: 'red' })
const root = document.createElement('div')
import {
getCurrentInstance,
- onMounted,
warn,
VNode,
Fragment,
Static,
- onUpdated,
- watchEffect
+ watchPostEffect,
+ onMounted,
+ onUnmounted
} from '@vue/runtime-core'
import { ShapeFlags } from '@vue/shared'
const setVars = () =>
setVarsOnVNode(instance.subTree, getter(instance.proxy!))
- onMounted(() => watchEffect(setVars, { flush: 'post' }))
- onUpdated(setVars)
+ watchPostEffect(setVars)
+ onMounted(() => {
+ const ob = new MutationObserver(setVars)
+ ob.observe(instance.subTree.el!.parentNode, { childList: true })
+ onUnmounted(() => ob.disconnect())
+ })
}
function setVarsOnVNode(vnode: VNode, vars: Record<string, string>) {