]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-dom): apply css vars before mount (#11538)
authorlinzhe <40790268+linzhe141@users.noreply.github.com>
Wed, 7 Aug 2024 03:51:44 +0000 (11:51 +0800)
committerGitHub <noreply@github.com>
Wed, 7 Aug 2024 03:51:44 +0000 (11:51 +0800)
fix #11533

packages/runtime-dom/src/helpers/useCssVars.ts

index 286a4176076889d7ebacc8a97f0a7c64dff79514..d2dcdb33f5297fd19e128593bf542b247a9e708d 100644 (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())