Răsfoiți Sursa

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

fix #11533
linzhe 1 an în urmă
părinte
comite
fdc2a31dbd
1 a modificat fișierele cu 5 adăugiri și 1 ștergeri
  1. 5 1
      packages/runtime-dom/src/helpers/useCssVars.ts

+ 5 - 1
packages/runtime-dom/src/helpers/useCssVars.ts

@@ -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())