Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(helpers): useCssVars race condition (fix #9264) #9368

Closed
wants to merge 1 commit into from

Conversation

OBe95
Copy link

@OBe95 OBe95 commented Oct 10, 2023

close #9264

Observations
It seems that the issue happens when there is a mount and directly unmount of the component
I noticed with the reproduction envs, that if I add an onBeforeUnmount hook, it's triggered before the onMounted which explains why the parentNode is undefined thus the error

I think checking the parentNode to be defined is enough, another solution might be to track the beforeUnmount hook and avoid plugging the observer

const ob = new MutationObserver(setVars)
ob.observe(instance.subTree.el!.parentNode, { childList: true })
onUnmounted(() => ob.disconnect())
if (instance.subTree.el?.parentNode) {
Copy link
Member

Choose a reason for hiding this comment

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

This modification can only solve the error report, but it does not solve the conflict between the execution of side-effect functions. From the example given by posva, we can see that the order of life cycle execution is not as expected. Unless we understand that this phenomenon is due to a side effect, causing the icon component to be unmounted first and then mounted again, so I am not sure whether this PR really solves the problem.
https://deploy-preview-9368--vue-sfc-playground.netlify.app/#eNqFVMlu2zAQ/RVWh1gGFOmQm+sEbdIUSIG2QZ3edGGkkaKEIgUusgNB/94hqS3OUh8scpY3j7N1wdemiVsDwSbYqkxWjSYKtGkIo7w8TwOt0uAi5VXdCKlJRyQUEdlTnT2QnhRS1CQN0D0NPk9GN5ngoypO7M0GWFp0xCi4MkqLeqeFhBkqTpwgtmHRPuXorZCSszo/cgvXCxMJtdDwjWqKdsgy7HqvdmTDlBMSrsn5hceK76mMZllnj4RYJMEgZqIMV5Odfy7I1dpbzZHiljJjeXHDGAYjpHegSUL2Qj5RKQzPN4OkIwUz6mFDVo1QekX6lHuCKS8Mz3SFWdOiLBl8FwJpOU6eRCEEBvk0XdANvVO+TXzJsEB40VA3jGrAGyHbe6M1In7JWJU92UKO0FjPO3cmNk7XLWL0/XqbeEcPkletO+DRVbU9rQrEmj1OThbpSAOSeL/EO26TBacgwmZCkKIq40clOHace2IaZKJuKgbyd2OTgJXfjAVJA8qY2P9wMi0NuPQ6nwfInt6QP6qDlaXBrQQFssW+m3SayhK0V1/vfsEBz5OyFrlhaP2B8g9gdxjL0ZtdYnWR9sLOsb1xTV7x8k5dHzRwNT7KEp2bxM3N1QdPn+mexWfOD8uOWRwn6nhkL1L55qBGRPBLKLBkf3mNHamt4Kc9QP5qiBEih6LicCtFo8LOCuxgMCEtNXcjRD83sCE7LfGV0ShEP2qYxgZHUjVWeDWo8L34teOInyMu4TiAQ5zFALqOOzLHGXRQ9t+jDQ/5P85guESY52eAW8yQw9mqhnKSMaoUtn2xP60QCwcIHVHhjJY9PqIo/Yzjhc3eQO6k8eA683P5bE/vK56H7uaz07+w3uQATaja0m4D51hUjL3rh6xsYBcR+2TcpNgnU1dAUUCmd5ZZhC1Cce207vTuVh/eBAeHMG2q4028zLwewuDOWsQLp6LZFaqN5IM2loa/LN8I4/eeXeYFZQr8U2e13c1ebffvrPUbH52jab0PmuMVDy6GbwmvR8xpq3cuq1Y69C5O5SAYHjBmcJwT+7NxX+C9AvHN1wf9P+Zbib0=

Copy link
Author

Choose a reason for hiding this comment

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

I agree I didn't dive into the root cause of the reversed order of the hooks

@edison1105
Copy link
Member

thanks for the PR but this is not the proper fix.
see #9370 (comment)

@OBe95 OBe95 closed this Oct 10, 2023
@OBe95 OBe95 deleted the fix-css-vars-observer branch October 10, 2023 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: dynamic css on dynamically imported component
3 participants