Skip to content

Commit 7feb523

Browse files
yyx990803lynxlangya
authored andcommitted
fix(hydration): handle edge case of style mismatch without style attribute
ref vuejs#10786
1 parent 0a3e6f5 commit 7feb523

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/runtime-core/__tests__/hydration.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,13 @@ describe('SSR hydration', () => {
15271527
expect(`Hydration style mismatch`).toHaveBeenWarnedTimes(1)
15281528
})
15291529

1530+
test('style mismatch when no style attribute is present', () => {
1531+
mountWithHydration(`<div></div>`, () =>
1532+
h('div', { style: { color: 'red' } }),
1533+
)
1534+
expect(`Hydration style mismatch`).toHaveBeenWarnedTimes(1)
1535+
})
1536+
15301537
test('style mismatch w/ v-show', () => {
15311538
mountWithHydration(`<div style="color:red;display:none"></div>`, () =>
15321539
withDirectives(createVNode('div', { style: 'color: red' }, ''), [

packages/runtime-core/src/hydration.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,8 @@ function propHasMismatch(
727727
): boolean {
728728
let mismatchType: string | undefined
729729
let mismatchKey: string | undefined
730-
let actual: any
731-
let expected: any
730+
let actual: string | boolean | null | undefined
731+
let expected: string | boolean | null | undefined
732732
if (key === 'class') {
733733
// classes might be in different order, but that doesn't affect cascade
734734
// so we just need to check if the class lists contain the same classes.
@@ -739,7 +739,7 @@ function propHasMismatch(
739739
}
740740
} else if (key === 'style') {
741741
// style might be in different order, but that doesn't affect cascade
742-
actual = el.getAttribute('style')
742+
actual = el.getAttribute('style') || ''
743743
expected = isString(clientValue)
744744
? clientValue
745745
: stringifyStyle(normalizeStyle(clientValue))

0 commit comments

Comments
 (0)