-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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(useCssVars): fix the loss of CSS variables during updates #9824
Conversation
Size ReportBundles
Usages
|
CodSpeed Performance ReportMerging #9824 will not alter performanceComparing Summary
|
// #9821 | ||
let cssVarText = (style as any)[CSS_VAR_TEXT] | ||
if (cssVarText) { | ||
cssVarText = (next.endsWith(';') ? '' : '; ') + cssVarText |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All mainstream browsers are able to handle extra ;
between properties in inline style, so we can just do ;(next as string) += ';' + cssVarText
and make cssVarText
a const.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have already made the modifications, thank you for your guidance.
fixed #9821
During the
patchStyle
process, if a string type is passed, it will overwrite the entirecssText
, leading to the loss of theuseCssVars
variable. InuseCssVars
, I store CSS variables in a private property of the style, which is then collectively set tocssText
during thepatchStyle
process.I attempted to use a
MutationObserver
to monitor style changes in all child elements. However, in the scenario where we also need to listen to thechildList
of theparentNode
, I had to add anotherMutationObserver
within theparentNode
's observer to simultaneously monitor newly added child elements. This approach introduces complexity to the logic, so I opted for the current solution.