fix(runtime-dom): apply css vars before mount (#11538)

fix #11533
This commit is contained in:
linzhe 2024-08-07 11:51:44 +08:00 committed by GitHub
parent e359ff0046
commit fdc2a31dbd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import {
Static,
type VNode,
getCurrentInstance,
onBeforeMount,
onMounted,
onUnmounted,
warn,
@ -42,8 +43,11 @@ export function useCssVars(getter: (ctx: any) => Record<string, string>) {
updateTeleports(vars)
}
onMounted(() => {
onBeforeMount(() => {
watchPostEffect(setVars)
})
onMounted(() => {
const ob = new MutationObserver(setVars)
ob.observe(instance.subTree.el!.parentNode, { childList: true })
onUnmounted(() => ob.disconnect())