-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
fix(hydration): avoid hydration mismatch on style variables with falsy values #12442
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
Changes from 6 commits
82a7559
c12af5d
95738bb
a29ba03
7d5a67a
86de253
e7ce297
8ce63aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -904,7 +904,7 @@ function toStyleMap(str: string): Map<string, string> { | |
let [key, value] = item.split(':') | ||
key = key.trim() | ||
value = value && value.trim() | ||
if (key && value) { | ||
if (key && isRenderableAttrValue(value)) { | ||
styleMap.set(key, value) | ||
} | ||
} | ||
|
@@ -938,10 +938,13 @@ function resolveCssVars( | |
) { | ||
const cssVars = instance.getCssVars() | ||
for (const key in cssVars) { | ||
expectedMap.set( | ||
`--${getEscapedCssVarName(key, false)}`, | ||
String(cssVars[key]), | ||
) | ||
const value = cssVars[key] | ||
if (isRenderableAttrValue(value)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And I think it's not semantically correct to use |
||
expectedMap.set( | ||
`--${getEscapedCssVarName(key, false)}`, | ||
String(value).trim(), | ||
) | ||
} | ||
} | ||
} | ||
if (vnode === root && instance.parent) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ import { | |
warn, | ||
watch, | ||
} from '@vue/runtime-core' | ||
import { NOOP, ShapeFlags } from '@vue/shared' | ||
import { NOOP, ShapeFlags, isRenderableAttrValue } from '@vue/shared' | ||
|
||
export const CSS_VAR_TEXT: unique symbol = Symbol(__DEV__ ? 'CSS_VAR_TEXT' : '') | ||
/** | ||
|
@@ -99,8 +99,12 @@ function setVarsOnNode(el: Node, vars: Record<string, string>) { | |
const style = (el as HTMLElement).style | ||
let cssText = '' | ||
for (const key in vars) { | ||
style.setProperty(`--${key}`, vars[key]) | ||
cssText += `--${key}: ${vars[key]};` | ||
const value = vars[key] | ||
if (isRenderableAttrValue(value)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A potential breaking change might have been introduced here. Previously, the client would render There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: I don’t think rendering This worked because undefined is never a valid value in CSS. In these scenarios where we want to unset and prevent inheritance, it should actually be set to a value of I was thinking you could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately setting the custom property to |
||
const trimVal = String(value).trim() | ||
style.setProperty(`--${key}`, trimVal) | ||
cssText += `--${key}: ${trimVal};` | ||
} | ||
} | ||
;(style as any)[CSS_VAR_TEXT] = cssText | ||
} | ||
|
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 don't think this is necessary,
value
here isstring | undefined
.