fix(hydration): handle edge case of style mismatch without style attribute

ref #10786
This commit is contained in:
Evan You 2024-05-06 15:38:16 -07:00
parent 481b1b6f38
commit f2c1412e46
No known key found for this signature in database
GPG Key ID: B9D421896CA450FB
2 changed files with 10 additions and 3 deletions

View File

@ -1527,6 +1527,13 @@ describe('SSR hydration', () => {
expect(`Hydration style mismatch`).toHaveBeenWarnedTimes(1)
})
test('style mismatch when no style attribute is present', () => {
mountWithHydration(`<div></div>`, () =>
h('div', { style: { color: 'red' } }),
)
expect(`Hydration style mismatch`).toHaveBeenWarnedTimes(1)
})
test('style mismatch w/ v-show', () => {
mountWithHydration(`<div style="color:red;display:none"></div>`, () =>
withDirectives(createVNode('div', { style: 'color: red' }, ''), [

View File

@ -727,8 +727,8 @@ function propHasMismatch(
): boolean {
let mismatchType: string | undefined
let mismatchKey: string | undefined
let actual: any
let expected: any
let actual: string | boolean | null | undefined
let expected: string | boolean | null | undefined
if (key === 'class') {
// classes might be in different order, but that doesn't affect cascade
// so we just need to check if the class lists contain the same classes.
@ -739,7 +739,7 @@ function propHasMismatch(
}
} else if (key === 'style') {
// style might be in different order, but that doesn't affect cascade
actual = el.getAttribute('style')
actual = el.getAttribute('style') || ''
expected = isString(clientValue)
? clientValue
: stringifyStyle(normalizeStyle(clientValue))