You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@edison1105 Yesterday, I wrote the same code as you to solve this issue, but when I delete the child of the teleport and then add the child to the teleport, the setVarsOnVNode function is not triggered.
Then I found that the MutationObserver in the useCssVars function is to observe the instance.subTree.el.parentNode, which is the DOM of #app,but the teleport child is atteched to the body 😂.
exportfunctionuseCssVars(getter: (ctx: any)=>Record<string,string>){if(!__BROWSER__&&!__TEST__)returnconstinstance=getCurrentInstance()/* istanbul ignore next */if(!instance){__DEV__&&warn(`useCssVars is called without current active component instance.`)return}constsetVars=()=>setVarsOnVNode(instance.subTree,getter(instance.proxy!))watchPostEffect(setVars)onMounted(()=>{constob=newMutationObserver(setVars)// In this case, the `instance.subTree.el!.parentNode` is equal to the DOM of `#app`ob.observe(instance.subTree.el!.parentNode,{childList: true})onUnmounted(()=>ob.disconnect())})}
I have also run into this issue. It took me a while to realize it's actually caused by teleport. Because sometimes you use a slot of either your or a third-party component and you don't know what exactly will happen to the content you're passing in. There can be teleport used inside and then you are wondering why v-bind doesn't work in your styles. It would be nice to have this fixed.
For example, Vue could detect a teleport somewhere down the component tree from where v-bind is used and then define CSS custom properties not only on the top-level component element but also on the child nodes inside teleport.
Activity
WJCHumble commentedon Sep 17, 2021
@edison1105 Yesterday, I wrote the same code as you to solve this issue, but when I delete the child of the
teleport
and then add the child to theteleport
, thesetVarsOnVNode
function is not triggered.Then I found that the
MutationObserver
in theuseCssVars
function is to observe theinstance.subTree.el.parentNode
, which is the DOM of#app
,but theteleport
child is atteched to thebody
😂.edison1105 commentedon Sep 17, 2021
@WJCHumble Good catch.
I will check it later.
livthomas commentedon Jan 20, 2022
I have also run into this issue. It took me a while to realize it's actually caused by teleport. Because sometimes you use a slot of either your or a third-party component and you don't know what exactly will happen to the content you're passing in. There can be teleport used inside and then you are wondering why
v-bind
doesn't work in your styles. It would be nice to have this fixed.For example, Vue could detect a teleport somewhere down the component tree from where
v-bind
is used and then define CSS custom properties not only on the top-level component element but also on the child nodes inside teleport.gyhyfj commentedon Sep 7, 2022
same problem
Rusinas commentedon Oct 22, 2022
Any updades on this? :(
daniluk4000 commentedon Oct 30, 2022
Same problem
fix(teleport/css-v-bind): fix css v-bind for teleported content
fix(teleport/css-v-bind): fix css v-bind for teleported content
fix(teleport/css-v-bind): fix css v-bind for teleported content