fix(sfc/style-vars): should attach css vars while subtree changed (#2178)

* fix(cssVars): should attach css vars while `subtree` changed

fix #2177

* fix: fix test
This commit is contained in:
underfin
2020-10-14 03:37:45 +08:00
committed by GitHub
parent bac4d22614
commit 408a8cad48
2 changed files with 33 additions and 7 deletions

View File

@@ -1,4 +1,5 @@
import {
ref,
render,
useCssVars,
h,
@@ -125,4 +126,29 @@ describe('useCssVars', () => {
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')
}
})
})