This commit is contained in:
yangxiuxiu 2025-05-05 20:38:32 +00:00 committed by GitHub
commit b6c9db7b91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 5 deletions

View File

@ -2204,6 +2204,31 @@ describe('SSR hydration', () => {
app.mount(container)
expect(`Hydration style mismatch`).not.toHaveBeenWarned()
})
test('style var with falsy values', () => {
const container = document.createElement('div')
container.innerHTML = `<div style="padding: 4px;--bar:;"></div>`
const app = createSSRApp({
setup() {
const value1 = ref<any>(null)
const value2 = ref('')
const value3 = ref<any>(undefined)
useCssVars(() => ({
foo: value1.value,
bar: value2.value,
baz: value3.value,
}))
return () => h(Child)
},
})
const Child = {
setup() {
return () => h('div', { style: 'padding: 4px' })
},
}
app.mount(container)
expect(`Hydration style mismatch`).not.toHaveBeenWarned()
})
})
describe('data-allow-mismatch', () => {

View File

@ -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) {
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)) {
expectedMap.set(
`--${getEscapedCssVarName(key, false)}`,
String(value).trim(),
)
}
}
}
if (vnode === root && instance.parent) {