Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(runtime-dom): before update should also set css vars #11561

Merged
merged 10 commits into from
Nov 14, 2024
5 changes: 5 additions & 0 deletions packages/runtime-dom/src/helpers/useCssVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
type VNode,
getCurrentInstance,
onBeforeMount,
onBeforeUpdate,
onMounted,
onUnmounted,
warn,
Expand Down Expand Up @@ -47,6 +48,10 @@ export function useCssVars(getter: (ctx: any) => Record<string, string>) {
watchPostEffect(setVars)
})

onBeforeUpdate(() => {
watchPostEffect(setVars)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should just call setVars and not create another watcher on each update.

Copy link
Contributor Author

@linzhe141 linzhe141 Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I just call setVars before update, the vnode is still a v-if comment, and it doesn't make sense to set custom properties for this comment.

image

But when I combine it with watchPostEffect, the vnode is correct.

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or use queuePostFlushCb instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

})

onMounted(() => {
const ob = new MutationObserver(setVars)
ob.observe(instance.subTree.el!.parentNode, { childList: true })
Expand Down