Skip to content

Commit 08b60f5

Browse files
authored
fix(hydration): improve mismatch when client valut is null or undefined (#10086)
1 parent bb6b7a2 commit 08b60f5

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,16 @@ describe('SSR hydration', () => {
15121512
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
15131513
})
15141514

1515+
test('client value is null or undefined', () => {
1516+
mountWithHydration(`<div></div>`, () =>
1517+
h('div', { draggable: undefined }),
1518+
)
1519+
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
1520+
1521+
mountWithHydration(`<input />`, () => h('input', { type: null }))
1522+
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
1523+
})
1524+
15151525
test('should not warn against object values', () => {
15161526
mountWithHydration(`<input />`, () => h('input', { from: {} }))
15171527
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()

packages/runtime-core/src/hydration.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,9 @@ function propHasMismatch(
758758
if (isBooleanAttr(key)) {
759759
actual = el.hasAttribute(key)
760760
expected = includeBooleanAttr(clientValue)
761+
} else if (clientValue == null) {
762+
actual = el.hasAttribute(key)
763+
expected = false
761764
} else {
762765
if (el.hasAttribute(key)) {
763766
actual = el.getAttribute(key)

0 commit comments

Comments
 (0)